1、显示当前系统上root、fedora或user1用户的默认shell;
[root@bogon ~]# cat /etc/passwd | grep -E "^(root|fedora|user1)\>" | cut -d: -f 7 /bin/bash /bin/bash
2、找出/etc/rc.d/init.d/functions文件中某单词后面跟一组小括号的行,形如:hello();
[root@bogon ~]# cat /etc/rc.d/init.d/functions | grep "\<[[:alpha:]]*()" | cut -d' ' -f1 checkpid() daemon() killproc() pidfileofproc() pidofproc() status() success() failure() passed() warning() action() strstr() confirm()
3、使用echo命令输出一个绝对路径,使用grep取出其基名;
[root@bogon ~]# echo "/etc/sysconfig/network-scripts/ifcfg-eth0" | grep -o "[^/]\+$" ifcfg-eth0
取出其路径名
[root@bogon ~]# echo "/etc/sysconfig/network-scripts/ifcfg-eth0" | grep -o "^.*/" /etc/sysconfig/network-scripts/
4、找出ifconfig命令结果中的1-255之间数字;
[root@bogon ~]# ifconfig | egrep -o "\<[1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-5][0-5]\>" 29 1 10 10 10 100 10 10 10 255 255 255 255 80 20 29 1 64 150
5、挑战题:写一个模式,能匹配合理的IP地址;
[root@bogon ~]# ifconfig | egrep -o "[1-9][0-9]?[0-9]?\.[0-9][0-9]?[0-9]?\.[0-9][0-9]?[0-9]?\.[0-9][0-9]?[0-9]?" 10.10.10.100 10.10.10.255 255.255.255.0 10.10.10.101 255.255.255.0 192.168.1.234 255.255.255.0 127.0.0.1 255.0.0.0
6、挑战题:写一个模式,能匹配出所有的邮件地址;
[root@bogon ~]# cat mail.txt asbd@qq.com dsaf@139.com mage@edu.com test@163.com dhskhdkf kskshgksjgdh [root@bogon ~]# cat mail.txt | egrep "[[:alnum:]]+@[[:alnum:]]+" asbd@qq.com dsaf@139.com mage@edu.com test@163.com
7、查找/var目录下属主为root,且属组为mail的所有文件或目录;
[root@bogon ~]# find /var -user root -group mail -ls 263166 4 drwxrwxr-x 2 root mail 4096 Nov 28 04:17 /var/spool/mail 263915 72 -rw------- 1 root mail 72437 Jun 3 02:00 /var/spool/mail/root
8、查找当前系统上没有属主或属组的文件;
[root@bogon ~]# find / -nouser -o -nogroup /test.txt /test /root/nload-0.7.2 /root/nload-0.7.2/install-sh /root/nload-0.7.2/aclocal.m4 /root/nload-0.7.2/ChangeLog ...... [root@bogon ~]# ll /test.txt -rw-r--r-- 1 5025 5025 15 Nov 21 13:01 /test.txt
查找当前系统上没有属主或属组,且最近3天内曾被访问过的文件或目录;
[root@bogon ~]# find / -nouser -o -nogroup -a -atime -3 /test.txt /test /root/test.txt ......
9、查找/etc目录下所有用户都有写权限的文件;
[root@bogon ~]# touch /etc/test.txt [root@bogon ~]# chmod 666 /etc/test.txt [root@bogon ~]# find /etc -type f -perm -222 -ls 396003 4 -rw-rw-rw- 1 root root 7 Nov 28 06:39 /etc/test.txt
10、查找/etc目录下大于1M,且类型为普通文件的所有文件;
[root@bogon ~]# find /etc -type f -size +1M -ls 394863 7124 -rw-r--r-- 1 root root 7292689 Jan 21 2015 /etc/selinux/targeted/modules/active/policy.kern 394866 7124 -rw-r--r-- 1 root root 7292689 Jan 21 2015 /etc/selinux/targeted/policy/policy.24 395770 1332 -rw-r--r-- 1 root root 1362271 Jan 28 2015 /etc/gconf/gconf.xml.defaults/%gconf-tree.xml
11、查找/etc/init.d/目录下,所有用户都有执行权限,且其它用户有写权限的文件;
[root@bogon init.d]# find /etc/init.d/ -type f -perm -113 -ls 394214 0 -rwxr-xrwx 1 root root 0 Nov 28 22:17 /etc/init.d/test.txt 396004 0 -rwxr-x-wx 1 root root 0 Nov 28 22:17 /etc/init.d/test2.txt
12、查找/usr目录下不属于root、bin或hadoop的文件;
[root@bogon ~]# find /usr/ -type f -not \( -user root -o -user bin -o -user hadoop \) -ls 1450330 0 -rw-r--r-- 1 user1 user1 0 Nov 21 12:47 /usr/test 1469800 12 -rwsr-xr-x 1 abrt abrt 9904 Nov 23 2013 /usr/libexec/abrt-action-install-debuginfo-to-abrt-cache
13、查找/etc/目录下至少有一类用户没有写权限的文件;
[root@bogon ~]# find /etc/ -type f -not -perm -222 -ls | head -10 393969 4 -rwxr-xr-x 1 root root 233 Mar 18 2015 /etc/rc.d/rc.local 393962 8 -rwxr-xr-x 1 root root 5866 Oct 10 2013 /etc/rc.d/init.d/halt 393865 4 -rwxr-xr-x 1 root root 1698 Nov 23 2013 /etc/rc.d/init.d/sandbox 394410 8 -rwxr-xr-x 1 root root 4621 Nov 13 2014 /etc/rc.d/init.d/sshd 395010 4 -rwxr-xr-x 1 root root 2276 Apr 2 2013 /etc/rc.d/init.d/svnserve 393878 12 -rwxr-xr-x 1 root root 10688 Nov 23 2013 /etc/rc.d/init.d/iptables 394529 4 -rwxr-xr-x 1 root root 4043 Nov 23 2013 /etc/rc.d/init.d/autofs 394583 4 -rwxr-xr-x 1 root root 3245 Jul 9 2013 /etc/rc.d/init.d/firstboot 394165 4 -rwxr-xr-x 1 root root 2305 Nov 22 2013 /etc/rc.d/init.d/rpcidmapd 393916 4 -rwxr-xr-x 1 root root 1513 Sep 17 2013 /etc/rc.d/init.d/rdisc
14、查找/etc目录下最近一周内其内容被修改过,且不属于root或hadoop的文件;
[root@bogon ~]# chown user1:user1 /etc/test.txt [root@bogon ~]# [root@bogon ~]# find /etc/ -type f -mtime -7 -not \( -user root -o -user hadoop \) -ls 396003 4 -rw-rw-rw- 1 user1 user1 7 Nov 28 06:39 /etc/test.txt
原创文章,作者:凸b男波万,如若转载,请注明出处:http://www.178linux.com/45317