马哥教育网络班21期-第五周课程练习

1、显示/boot/grub/grub.conf中以至少一个空白字符开头的行;

[root@localhost ~]# grep "^[[:space:]]\{1,\}" /boot/grub/grub.conf

2、显示/etc/rc.d/rc.sysinit文件中以#开头,后面跟至少一个空白字符,而后又有至少一个非空白字符的行;

[root@localhost ~]# grep "^#[[:space:]]\{1,\}[^[:space:]]\{1,\}" /etc/rc.d/rc.sysinit

3、打出netstat -tan命令执行结果中以‘LISTEN’,后或跟空白字符结尾的行;

[root@localhost ~]# netstat -tan | egrep "(\<LISTEN\>|[[:space:]])$"

4、添加用户bash, testbash, basher, nologin (此一个用户的shell为/sbin/nologin),而后找出当前系统上其用户名和默认shell相同的用户的信息;

#!/bin/bash
#

for user in bash testbash basher nologin;do
    id $user &> null
    if [ $? -eq 0];then
        echo "$user is exist"
    else
        if [ $user != nologin ];then
                useradd $user
        else
                useradd -s /sbin/nologin $user
        fi
    fi
done

grep "^\(\<[[:alnum:]]\+\>\):.*\1$" /etc/passwd | cut -d: -f1

5、显示当前系统上root、fedora或user1用户的默认shell;

[root@localhost ~]# for user in root fedora user1;do grep "^$user" /etc/passwd | cut -d: -f1,7;done

6、找出/etc/rc.d/init.d/functions文件中某单词后面跟一组小括号的行,形如:hello();

[root@localhost ~]# grep "\<[[:alpha:]]\+\>()" /etc/rc.d/init.d/functions

7、使用echo命令输出一个绝对路径,使用grep取出其基名;

    扩展:取出其路径名

[root@localhost games]# echo /usr/local/ga1mes | grep -o "\<[[:alnum:]]\+\>$"  #取基名
[root@localhost games]# echo "/usr/local/games" | grep -o "^\/.*\/"  #取路径名

8、找出ifconfig命令结果中的1-255之间数字;

[root@localhost games]# ifconfig eth0 | egrep -o "\<[1-9]\>|\<[1-9][0-9]\>|\<1[0-9][0-9]\>|\<2[0-4][0-9]\>|25[0-5]"

9、挑战题:写一个模式,能匹配合理的IP地址;

[root@localhost ~]# ifconfig eth0 | egrep -o "(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])"

10、挑战题:写一个模式,能匹配出所有的邮件地址;

[root@localhost ~]# echo la1y_123@126x.com | grep "[[:alnum:]_]\+@[[:alnum:]]\+\.[[:alpha:]]\{2,\}"

11、查找/var目录下属主为root,且属组为mail的所有文件或目录;

[root@localhost games]# find /var -user root -group mail

12、查找当前系统上没有属主或属组的文件;

     进一步:查找当前系统上没有属主或属组,且最近3天内曾被访问过的文件或目录;

a. [root@localhost ~]# find / -nouser -o -nogroup
b. [root@localhost ~]# find / -nouser -o -nogroup -atime -3

13、查找/etc目录下所有用户都有写权限的文件;

[root@localhost ~]# find /etc -perm  -2

14、查找/etc目录下大于1M,且类型为普通文件的所有文件;

[root@localhost ~]# find /etc -size +1M -type f

15、查找/etc/init.d/目录下,所有用户都有执行权限,且其它用户有写权限的文件;

[root@localhost ~]# find /etc/init.d/ -perm -113

16、查找/usr目录下不属于root、bin或hadoop的文件;

[root@localhost ~]# find /usr -not \( -user root -o -user bin -o -user hadoop \)

17、查找/etc/目录下至少有一类用户没有写权限的文件;

[root@localhost ~]# find /etc/ -not  -perm /2

18、查找/etc目录下最近一周内其内容被修改过,且不属于root或hadoop的文件

[root@localhost ~]# find /etc/ -mtime -7 -not \( -user root -o -user hadoop \)

原创文章,作者:Net21_木头,如若转载,请注明出处:http://www.178linux.com/30677

(0)
Net21_木头Net21_木头
上一篇 2016-08-08 16:11
下一篇 2016-08-08 16:11

相关推荐

  • N26 第二周

    1、Linux上的文件管理类命令都有哪些,其常用的使用方法及其相关示例演示。  [1]mkdir : make directories            mkdir [OPTION]… DIRECTORY… &n…

    Linux干货 2017-02-05
  • 软件安装与管理–rpm、yum

    一、rpm包管理器     1、介绍rpm        在linux系统中,服务是要通过程序来提供的,通过调用API接口编写好之后的源码包文件对于普通用户来说,安装起来较为繁琐。于是人们将源码在编译安装的环境下制作了更加高级的rpm包,它的最大特点是避免了对原软件包的编译安装,以更加简便…

    Linux干货 2016-08-22
  • 三.Linux博客-2016年7月24日帮助、history、别名、tree

    格式说明: 操作 概念 命令 说明及举例 三-1.帮助、history、别名、tree touch /etc/nologin 使普通用户不能登录(创建了一个文件,删掉就可以登陆)   ll /etc/nologin 查看那个文件 -rm -f /etc/  删…

    Linux干货 2016-08-23
  • linux时间设置、screen使用、命令分类、hash作用、命令引用及history命令

    一、 生产环境发现一台服务器系统时间产生偏差,造成服务异常 解决方法             a、 如果服务器硬件时间准备的话,可使用命令:~#] hwclock -s              将硬件时钟同步到系统 &…

    Linux干货 2013-06-11
  • N21-天天-第九周课程练习

    1、写一个脚本,判断当前系统上所有用户的shell是否为可登录shell(即用户的shell不是/sbin/nologin);分别这两类用户的个数;通过字符串比较来实现; #!/bin/bash awk -F: '$NF~"/sbin/nologin" {shell++} $NF!~&qu…

    Linux干货 2016-09-01
  • Linux终端和伪终端简述

    本文简述Linux各种类型终端的区别以及如何用命令查看终端类型

    Linux干货 2018-03-26

评论列表(1条)

  • 马哥教育
    马哥教育 2016-08-17 15:37

    写的很好,排版也很棒,加油