1顯示當前系統上root,fedora或user1用戶的默認shell
egrep "^(root|user1|fedora)" /etc/passwd|cut -d ':' -f 1,7
2找出/etc/rc.d/init.d/functions文件中某個單詞后面跟一組小括號的行,形如hello();
grep -o ".\+()" /etc/rc.d/init.d/functions egrep -o ".+\(\)" /etc/rc.d/init.d/functions
3使用echo命令輸出絕對路徑,使用grep取出其基名 擴展:取出其路徑名
echo $(pwd)|grep -o "[^/]\+/\?$" echo $(pwd)|grep -o "[[:alnum:]]\+.*/"
4找出ifconfig命令結果中的1-255之間數字
ifconfig| grep -E "\<([1-9][0-9]?|[1][0-9]{2}|[2][0-4][0-9]|[2][5][0-5])\>"
5挑戰題:寫一個模式,能匹配合理的ip地址
ifconfig| grep -oE "(\<([1-9][0-9]?|[1][0-9]{2}|[2][0-4][0-9]|[2][5][0-5])\>\.){2}([1-9][0-9]?|[1][0-9]{2}|[2][0-4][0-9]|[2][5][0-5])"
6寫一個模式,能匹配所有的郵件地址
egrep -o "[[:alnum:]]+@[[:alnum:]]+.*\.[[:alnum:]]+"
7查找/var目錄下的屬主為root,且屬組為mail的所有文件或目錄
find /var -user root -group mail -ls
8查找當前系統上沒有屬主或屬組的文件,查找當前目錄下沒有屬主或屬組,且最近3天內曾被訪問過的文件或目錄
find / (-nouser -o -nogroup) -ls 注意:為了避免Shell本身對括號引起誤解,在話號前需要加轉義字符“\”來去除括號的意義 修正:find / \( -nouser -o -nogroup \) -ls find / \( -nouser -o -nogroup \) -atime -3 -ls
9查找/etc目錄下所有用戶都有寫權限的文件
find /etc -perm -222 -ls
10查找/etc目錄下大于1M,且類型為普通文件的所有文件
find /etc -size +1M -type f -ls
11查找/etc/init.d/目錄下,所有用戶都有執行權限,且其它用戶有寫權限的文件
find /etc/init.d/ -perm -113 -ls
12查找/usr目錄下不屬于root,bin或hadoop的文件
find /usr -not -user root -a -not -user bin -a -not -user hadoop find /usr -not \( -user root -o -user bin -o -user hadoop \)
13查找/etc/目錄下至少有一類用戶沒有寫權限的文件
find /etc -not -perm -222 -ls
14查找/etc目錄下最近一周內其內容被修改過,且不屬于root或hadoop的文件
find /etc -atime -7 -a \( -not -user root -o -not -user hadoop \) find /etc -atime -7 -a -not \( -user root -a -user hadoop \)
原創文章,作者:N24-超,如若轉載,請注明出處:http://www.www58058.com/63381
贊,第8小題注意下,其它都不錯,繼續加油~