第五週作業


1、顯示當前系統上root、fedora或user1用戶的默認shell;

    egrep "^root|^fedora|^user1" /etc/passwd | cut -d: -f 1,7


2、找出/etc/rc.d/init.d/functions文件中某單詞後面跟一組小括號的行,形如:hello();

   

 grep "\<[[:alpha:]]\+\>()" /etc/rc.d/init.d/functions



3、使用echo命令輸出一個絕對路徑,使用grep取出其基名;

    echo "/var/log/messages"|grep -o "[[:alnum:]]\+$"

擴展:取出其路徑名

   

 echo "/var/log/messages" |egrep -o ".*/"



4、找出ifconfig命令結果中的1-255之間數字;

   

 ifconfig | egrep -o  "\<[1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]\>"



5、挑戰題:寫一個模式,能匹配合理的IP地址;

   

 ifconfig | egrep -o  "((\<[1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]\>).){3}(\<[1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]\>)"

6、挑戰題:寫一個模式,能匹配出所有的郵件地址

   

 egrep "[[:alnum:]]+[[:punct:]]*.*@[[:alnum:]]+[[:punct:]]*\.[[:alpha:]]"

7、查找/var目錄下屬主爲root,且屬組爲mail的所有文件或目錄;

   

 find /var -user root -group mail -print


8、查找當前系統上沒有屬主或屬組的文件;

   

 find / -nouser -o -nogroup -print -exec ls -l {} \;


9、查找/etc目錄下所有用戶都有寫權限的文件;

    

find /etc -perm -ugo=x -type f -exec ls -l {} \;

10、查找/etc目錄下大於1M,且類型爲普通文件的所有文件;

    

find /etc/ -size +1M -type f -exec ls -hl {} \;


11、查找/etc/init.d/目錄下,所有用戶都有執行權限,且其它用戶有寫權限的文件;

    

find /etc/init.d -perm -ug=x,o=wx -type f -exec ls -l {} \;


12、查找/usr目錄下不屬於root、bin或hadoop的文件;

    

find /usr ! -user root ! -user bin ! -user hadoop -type f

13、查找/etc/目錄下至少有一類用戶沒有寫權限的文件;

    

find /etc/  -perm +ugo=w  -type f -exec ls -l {} \;


14、查找/etc目錄下最近一週內其內容被修改過,且不屬於root或hadoop的文件;

   

 find /etc -mtime -7  ! -user root ! -user hadoop -type f
 

 
 
 Never Ending...


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章