1、顯示當前系統上root、fedora或user1用戶的默認shell
[root@MyCloudServer wjb]# egrep '^(root|fedora|user1)\>' /etc/passwd | cut -d: -f7
/bin/bash
2、找出/etc/rc.d/init.d/functions文件中某單詞后面跟一級小括號的行,形如:hello()
[root@MyCloudServer ~]# grep '\<[[:alpah:]]\+()' /etc/rc.d/init.d/functions
3、使用echo命令輸出一個絕對路徑,使用grep取出其基名,擴展:取出其路徑名
[root@MyCloudServer ~]# echo "/etc/passwd" | egrep -o "[^/]+/?$"
passwd
[root@MyCloudServer ~]# echo "/etc/passwd" | egrep -o ".*/"
/etc/
4、找出ifconfig命令結果中的1-255之間數字
[root@MyCloudServer ~]# ifconfig | egrep -o '\<[1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-5][0-5]\>'
4
21
122
10
5、挑戰題:寫一個模式,能匹配合理的IP地址
[root@MyCloudServer ~]# ifconfig | egrep -o '[1-9]{3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'
122.10.117.47
122.10.117.127
255.255.255.128
127.0.0.1
255.0.0.0
6、挑戰題:寫一個模式,能匹配出所有的郵件地址
[root@MyCloudServer ~]# /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i
7、查找/var目錄下屬主為root,且屬組為mail的所有文件或目錄
[root@MyCloudServer ~]# find /var/ -user root -group mail
/var/spool/mail
8、查找當前系統上沒有屬主或屬組的文件,進一步:查找當前系統上沒有屬主或屬級,且最近3天內曾被訪問過的文件或目錄
[root@MyCloudServer ~]# find / -nouser -a -nogroup
[root@MyCloudServer ~]# find / -nouser -a -nogroup -mtime -3
9、查找/etc目錄下所有用戶都有寫權限的文件
[root@MyCloudServer ~]# find /etc -perm -222 -ls
132257 0 lrwxrwxrwx 1 root root 15 Apr 30 2013 /etc/rc.sysinit -> rc.d/rc.sysinit
132258 0 lrwxrwxrwx 1 root root 10 Apr 30 2013 /etc/rc0.d -> rc.d/rc0.d
132272 0 lrwxrwxrwx 1 root root 11 Apr 30 2013 /etc/sysconfig/network-scripts/ifdown-isdn -> ifdown-ippp
132267
0 lrwxrwxrwx 1 root root 20 Apr 30 2013
/etc/sysconfig/network-scripts/ifdown -> ../../../sbin/ifdown
…..
10、查找/etc目錄下大于1M,且類型為變通文件的所有文件
[root@MyCloudServer ~]# find /etc/ -type f -a -size +1M
/etc/selinux/targeted/policy/policy.24
/etc/selinux/targeted/modules/active/policy.kern
11、查找/etc/init.d/目錄下,所有用戶都有執行權限,且其它用戶有寫權限的文件
[root@MyCloudServer ~]# find /etc/init.d/ -perm -113 -ls
12、查找/usr目錄下不屬于root、bin或hadoop的文件
[root@MyCloudServer ~]# find /usr/ -not \( -user root -o -user bin -o -user hadoop \) -ls
13、查找/etc/目錄下至少有一類用戶沒有寫權限的文件
[root@MyCloudServer ~]# find /etc/ -not -perm -222
14、查找/etc目錄下最近一周內其內容被修改過,且不屬于root或hadoop的文件
[root@MyCloudServer ~]# find /etc/ -mtime -7 -a -not \( -user root -o -user hadoop \) -ls
原創文章,作者:wangjinbao5566,如若轉載,請注明出處:http://www.www58058.com/45755