作業要求:
1、顯示/boot/grub/grub.conf中以至少一個空白字符開頭的行;
2、顯示/etc/rc.d/rc.sysinit文件中以#開頭,后面跟至少一個空白字符,而后又有至少一個非空白字符的行;
3、打出netstat -tan命令執行結果中以‘LISTEN’,后或跟空白字符結尾的行;
4、添加用戶bash, testbash, basher, nologin (此一個用戶的shell為/sbin/nologin),而后找出當前系統上其用戶名和默認shell相同的用戶的信息;
5、顯示當前系統上root、fedora或user1用戶的默認shell;
6、找出/etc/rc.d/init.d/functions文件中某單詞后面跟一組小括號的行,形如:hello();
7、使用echo命令輸出一個絕對路徑,使用grep取出其基名;
擴展:取出其路徑名
8、找出ifconfig命令結果中的1-255之間數字;
9、挑戰題:寫一個模式,能匹配合理的IP地址;
10、挑戰題:寫一個模式,能匹配出所有的郵件地址;
11、查找/var目錄下屬主為root,且屬組為mail的所有文件或目錄;
12、查找當前系統上沒有屬主或屬組的文件;
進一步:查找當前系統上沒有屬主或屬組,且最近3天內曾被訪問過的文件或目錄;
13、查找/etc目錄下所有用戶都有寫權限的文件;
14、查找/etc目錄下大于1M,且類型為普通文件的所有文件;
15、查找/etc/init.d/目錄下,所有用戶都有執行權限,且其它用戶有寫權限的文件;
16、查找/usr目錄下不屬于root、bin或hadoop的文件;
17、查找/etc/目錄下至少有一類用戶沒有寫權限的文件;
18、查找/etc目錄下最近一周內其內容被修改過,且不屬于root或hadoop的文件;
1、顯示/boot/grub/grub.conf中以至少一個空白字符開頭的行;
[root@localhost /]# grep "^[[:space:]]\+" /boot/grub/grub.conf root (hd0,0) kernel /vmlinuz-2.6.32-504.el6.x86_64 ro root=UUID=aa5cf6b3-e1b5-4eb2-95e6-e202f2890edf rd_NO_LUKS rd_NO_LVM LA NG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet initrd /initramfs-2.6.32-504.el6.x86_64.img
2、顯示/etc/rc.d/rc.sysinit文件中以#開頭,后面跟至少一個空白字符,而后又有至少一個非空白字符的行;
[root@localhost /]# grep "^#[[:space:]]\+[^[:space:]]" /etc/rc.d/rc.sysinit
3、打出netstat -tan命令執行結果中以‘LISTEN’,后或跟空白字符結尾的行;
[root@localhost /]# netstat -tan | grep "LISTEN[[:space:]]*$" tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN tcp 0 0 :::22 :::* LISTEN tcp 0 0 ::1:631 :::* LISTEN tcp 0 0 ::1:25 :::* LISTEN [root@localhost /]#
4、添加用戶bash, testbash, basher, nologin (此一個用戶的shell為/sbin/nologin),而后找出當前系統上其用戶名和默認shell相同的用戶的信息;
[root@localhost /]# grep -E '^(\<[a-z]+\>).*\1$' /etc/passwd sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/sbin:/sbin/halt nologin:x:501:501::/home/nologin:/sbin/nologin bash:x:502:502::/home/bash:/bin/bash [root@localhost /]#
5、顯示當前系統上root、fedora或user1用戶的默認shell;
[root@localhost /]# grep -E '^(root|fedora|user1)' /etc/passwd root:x:0:0:root:/root:/bin/bash [root@localhost /]#
6、找出/etc/rc.d/init.d/functions文件中某單詞后面跟一組小括號的行,形如:hello();
[root@localhost /]# grep -E "[a-z]+\(\)" /etc/rc.d/init.d/functions
7、使用echo命令輸出一個絕對路徑,使用grep取出其基名;
擴展:取出其路徑名
[root@localhost network-scripts]# echo /etc/sysconfig/network-scripts | grep -o "[^/]*$" network-scripts [root@localhost network-scripts]# echo /etc/sysconfig/network-scripts | grep -oP "^.*(?=/)" /etc/sysconfig [root@localhost network-scripts]#
8、找出ifconfig命令結果中的1-255之間數字;
[root@localhost ~]# ifconfig | egrep -o "[1-9]{1,2}|2[0-5]{1,2}"
9、挑戰題:寫一個模式,能匹配合理的IP地址;
[root@localhost ~]# ifconfig | egrep -o "[1-9]{1,3}\.[1-9]{1,3}\.[1-9]{1,3}\.[1-9]{1,3}" 192.168.1.8 192.168.1.255 192.168.1.25 192.168.253.135 192.168.253.255 192.168.253.25 [root@localhost ~]# 備注:這寫法會匹配888.888.888.888之類的數字,但是ifconfig的結果中以點分十進制數字中不會出現此類數字??!偷懶的寫法
10、挑戰題:寫一個模式,能匹配出所有的郵件地址;
[root@localhost ~]# cat mail.txt | grep '[[:alnum:]]\+@[[:alnum:]]\+\.[[:alnum:]]\+$' mfchangs@126.com mfchangs@sina.com mfchangs@qq.com mfchangs100@sina.com [root@localhost ~]# cat mail.txt 123456@adadf mfchangs@126.com mfchangs@sina.com mfchangs@qq.com akjdflajf@qqajdlaflk mfchangs100@sina.com [root@localhost ~]#
11、查找/var目錄下屬主為root,且屬組為mail的所有文件或目錄;
[root@localhost ~]# find /var -user root -group mail /var/spool/mail /var/spool/mail/root [root@localhost ~]#
12、查找當前系統上沒有屬主或屬組的文件;
進一步:查找當前系統上沒有屬主或屬組,且最近3天內曾被訪問過的文件或目錄;
[root@localhost /]# find / -nouser -o -nogroup [root@localhost ~]# find / -nouser -o -nogroup -a -atime 3
13、查找/etc目錄下所有用戶都有寫權限的文件;
[root@localhost ~]# find /etc -perm -222 -ls
14、查找/etc目錄下大于1M,且類型為普通文件的所有文件;
[root@localhost ~]# find /etc -type f -size +1M -ls 668012 7892 -rw-r--r-- 1 root root 8080653 Jul 4 08:37 /etc/selinux/targeted/modules/active/policy.kern 668019 7892 -rw-r--r-- 1 root root 8080653 Jul 4 08:37 /etc/selinux/targeted/policy/policy.24 794284 1976 -rw-r--r-- 1 root root 2020885 Jul 4 08:34 /etc/gconf/gconf.xml.defaults/%gconf-tree.xml [root@localhost ~]#
15、查找/etc/init.d/目錄下,所有用戶都有執行權限,且其它用戶有寫權限的文件;
[root@localhost ~]# find /etc/init.d/ -type f -perm -102 -ls 663307 0 -rwxrwxrwx 1 root root 0 Jul 9 17:20 /etc/init.d/test.txt
16、查找/usr目錄下不屬于root、bin或hadoop的文件;
[root@localhost ~]# touch /usr/2.txt [root@localhost ~]# chown test:test /usr/2.txt [root@localhost ~]# find /usr/ -type f ! \( -user root -o -user bin -o -user hadoop \) -ls 400099 12 -rwsr-xr-x 1 abrt abrt 10296 Oct 16 2014 /usr/libexec/abrt-action-install-debuginfo-to-abrt-cache 395439 0 -rw-r--r-- 1 test test 0 Jul 9 17:29 /usr/2.txt [root@localhost ~]#
17、查找/etc/目錄下至少有一類用戶沒有寫權限的文件;
[root@localhost ~]# find /etc/ ! -perm +222 -ls
18、查找/etc目錄下最近一周內其內容被修改過,且不屬于root或hadoop的文件;
[root@localhost ~]# find /etc/ -type f -ctime -7 -a ! \( -user root -o -user hadoop \) -ls 663346 4 -rw-r--r-- 1 test test 2 Jul 9 17:37 /etc/2.txt [root@localhost ~]#
原創文章,作者:Net20-deamon,如若轉載,請注明出處:http://www.www58058.com/23356
寫的很好,排版也很棒,加油