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

    [root@bogon ~]# grep -E "^root\>|^fedora\>|^user1\>" /etc/passwd
    root:x:0:0:root:/root:/bin/bash
    fedora:x:3004:3004::/home/fedora:/bin/bash
    user1:x:3005:3005::/home/user1:/bin/bash
    
     [root@bogon ~]# grep -E "^root\>|^fedora\>|^user1\>" /etc/passwd | cut -d: -f1,7
     root:/bin/bash
     fedora:/bin/bash
     user1:/bin/bash

2、找出/etc/rc.d/init.d/functions文件中某单词后面跟一组小括号的行,

    形如:hello();

    [root@bogon ~]# grep -o "[[:alpha:]]\+()" /etc/rc.d/init.d/functions
    checkpid()
    run()
    pidof()
    daemon()
    killproc()
    pidfileofproc()
    pidofproc()
    status()
    success()
    failure()
    passed()
    warning()
    stage()
    success()
    failure()
    passed()
    warning()
    action()
    strstr()
    file()
    true()
    false()
    sysctl()

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

    扩展:取出其路径名

   使用grep取出其基名
   [root@bogon ~]# echo "/tmp/yu/test"| grep -Eo "[^/]+/?$"
   test
       
   取出其路径名
    [root@bogon ~]# echo "/tmp/yu/test/test.txt" | grep -o "/[[:alpha:]]\+.*/"
    /tmp/yu/test/

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

 一、查看ifconfig命令结果
[root@bogon ~]# ifconfig
        eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
                inet 192.168.0.104  netmask 255.255.255.0  broadcast 192.168.0.255
                inet6 fe80::20c:29ff:fe38:81b3  prefixlen 64  scopeid 0x20<link>
                ether 00:0c:29:38:81:b3  txqueuelen 1000  (Ethernet)
                RX packets 1488  bytes 134194 (131.0 KiB)
                RX errors 0  dropped 0  overruns 0  frame 0
                TX packets 882  bytes 100702 (98.3 KiB)
                TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        
        lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
                inet 127.0.0.1  netmask 255.0.0.0
                inet6 ::1  prefixlen 128  scopeid 0x10<host>
                loop  txqueuelen 0  (Local Loopback)
                RX packets 0  bytes 0 (0.0 B)
                RX errors 0  dropped 0  overruns 0  frame 0
                TX packets 0  bytes 0 (0.0 B)
                TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
                
    二、查看ifconfig命令结果中1-255之间数字
[root@bogon ~]# ifconfig | egrep -o "\<[1-9]\>|\<[1-9][0-9]\>|\<[1][0-9][0-9]\>|\<[2][0-4][0-9]\>|\<[2][5][0-5]\>"

 192
 168
 104
 255
 255
 255
 192
 168
 255
 64
 29
 38
 81
 168
 9
 126
 9
 73
 127
 1
 255
 1
 128

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

[root@bogon ~]# ifconfig | egrep -o "(\<[1-9]\>|\<[1-9][0-9]\>|\<[1][0-9][0-9]\>|\<[2][0-4][0-9]\>|\<[2][5][0-5]\>)\.(\<[0-9]\>|\<[1-9][0-9]\>|\<[1][0-9][0-9]\>|\<[2][0-4][0-9]\>|\<[2][5][0-5]\>)\.(\<[0-9]\>|\<[1-9][0-9]\>|\<[1][0-9][0-9]\>|\<[2][0-4][0-9]\>|\<[2][5][0-5]\>).(\<[0-9]\>|\<[1-9][0-9]\>|\<[1][0-9][0-9]\>|\<[2][0-4][0-9]\>|\<[2][5][0-5]\>)"

 192.168.0.104
 255.255.255.0
 192.168.0.255
 127.0.0.1
 255.0.0.0

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

[root@bogon ~]# echo " 10000000@qq.com" | grep -o  "\<[0-9a-zA-Z]\+.*@[0-9a-z]\+\.[[:alpha:]]\+\>"

 10000000@qq.com

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

[root@bogon ~]# find /var -user root -group mail -ls
67150324    4 drwxrwxr-x   2 root     mail         4096 9月  4 10:25 /var/spool/mail

8、查找当前系统上没有属主或属组的文件;进一步:查找当前系统上没有属主或属组,

   且最近3天内曾被访问过的文件或目录;

一、查找当前系统上没有属主或属组的文件
[root@bogon ~]#  find / \( -nouser -o -nogroup \) -ls
find: ‘/proc/2727/task/2727/fd/6’: 没有那个文件或目录
find: ‘/proc/2727/task/2727/fdinfo/6’: 没有那个文件或目录
find: ‘/proc/2727/fd/6’: 没有那个文件或目录
find: ‘/proc/2727/fdinfo/6’: 没有那个文件或目录
67987392 0 -rw-rw----  1 1005  mail     0 8月 27 19:23 /var/spool/mail/mandriva
13801   0 drwx------  2 1005  distro   59 8月 27 19:23 /home/mandriva
13802   4 -rw-r--r--  1 1005  distro   18 11月 20  2015 /home/mandriva/.bash_logout
13804   4 -rw-r--r--  1 1005  distro   193 11月 20  2015 /home/mandriva/.bash_profile
13805   4 -rw-r--r--  1 1005  distro    231 11月 20  2015 /home/mandriva/.bashrc

二、查找当前系统上没有属主或属组,且最近3天内曾被访问过的文件或目录;
[root@bogon ~]# find / \( -nouser -o -nogroup \) -a -atime 3 -ls
find: ‘/proc/2723/task/2723/fd/6’: 没有那个文件或目录
find: ‘/proc/2723/task/2723/fdinfo/6’: 没有那个文件或目录
find: ‘/proc/2723/fd/6’: 没有那个文件或目录
find: ‘/proc/2723/fdinfo/6’: 没有那个文件或目录

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

[yu@bogon root]$ find /var -perm -222 -ls
find: ‘/var/lib/yum/history/2016-07-31/1’: 权限不够
find: ‘/var/lib/yum/history/2016-07-31/2’: 权限不够
find: ‘/var/lib/yum/history/2016-07-31/3’: 权限不够


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

[root@bogon ~]# find /etc -size +1M -a -type f -ls
34456002 6824 -r--r--r-- 1 root root 6984832 7月 31 08:33 /etc/udev/hwdb.bin
67886850 3772 -rw-r--r-- 1 root root 3858924 11月 21  2015 /etc/selinux/targeted/policy/policy.29

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

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

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

[root@bogon ~]# find /usr -not -user root -a -not -user bin -a -not -user hadoop
/usr/share/polkit-1/rules.d

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

[root@bogon ~]# find /etc/ -not -perm -222

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

[root@bogon ~]#  find /etc/ -mtime -7 -a -not -user root -a -not -user hadoop