第五週:作業內容

顯示當前系統上rootfedorauser1用戶的默認shell

[root@hiall2016 /]# grep -E"^root\>|^fedora\>|^user1\>" /etc/passwd
root:x:0:0:root:/root:/bin/bash
fedora:x:1022:1024::/home/fedora:/bin/bash
user1:x:1023:1025::/home/user1:/bin/bash
[root@hiall2016 /]# grep –E  "^root\>|^fedora\>|^user1\>"/etc/passwd  | cut -d: -f1,7
root:/bin/bash
fedora:/bin/bash
user1:/bin/bash

        wKiom1fNKyPTaif0AACnou0IEUc945.png-wh_50                     





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

[root@hiall2016 /]#  grep -o "[[:alpha:]]\+()"/etc/rc.d/init.d/functions
checkpid()
run()
pidof()
daemon()
killproc()
pidfileofproc()
pidofproc()
status()
success()
failure()
passed()
warning()
stage()
success()
failure()
passed()
warning()
action()
strstr()
file()
true()
false()
sysctl()


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

擴展:取出其路徑名

擴展:取出其路徑名

[root@hiall2016 mytest1]# echo"/tmp/mytest1/ppp" |grep -Eo "[^/]+/?$"
Ppp


 取出其路徑名

[root@hiall2016 mytest1]# echo"/tmp/mytest1/ppp" | grep -o "/[[:alpha:]]\+.*/"
/tmp/mytest1/


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

 

[root@hiall2016 mytest1]# ifconfig
em1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
       inet 192.168.1.252  netmask255.255.255.0  broadcast 192.168.1.255
       inet6 fe80::7a2b:cbff:fe3f:710d prefixlen 64  scopeid0x20<link>
       ether 78:2b:cb:3f:71:0d txqueuelen 1000  (Ethernet)
       RX packets 4506052958  bytes381632573878 (355.4 GiB)
       RX errors 0  dropped 22637  overruns 0 frame 0
       TX packets 15272610830  bytes979169669462 (911.9 GiB)
       TX errors 0  dropped 0 overruns0  carrier 0  collisions 0

 


 [root@hiall2016 mytest1]# ifconfig | egrep -o"\<[1-9]\>|\<[1-9][0-9]\>|\<[1][0-9][0-9]\>|\<[2][0-4][0-9]\>|\<[2][5][0-5]\>"
192
168
1
252
255
255
255
192
168
1
255
64
78
71
4
9
192
168
1
253
255
255
255
192
168
1
255
64
78
71
78
71
11
78
71
13
73
127
1
255
1
128
16
3
16
3



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

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



 

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

 

[root@iZ25w7uckyyZ logs]# echo "[email protected]" | grep -o "\<[0-9a-zA-Z]\+.*@[0-9a-z]\+\.[[:alpha:]]\+\>"

[email protected]

 


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

[root@iZ25w7uckyyZ logs]# find /var -userroot -group mail -ls
393300   4 drwxrwxr-x   2 root     mail         4096 Jul 27 11:09 /var/spool/mail


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



 進一步:查找當前系統上沒有屬主或屬組,且最近3天內曾被訪問過的文件或目錄;

[root@iZ25w7uckyyZ logs]# find / \( -nouser-o -nogroup \) -a -atime 3 -ls
find: ‘/proc/1349/task/1349/fd/6’: No suchfile or directory
find: ‘/proc/1349/task/1349/fdinfo/6’: Nosuch file or directory
find: ‘/proc/1349/fd/6’: No such file ordirectory
find: ‘/proc/1349/fdinfo/6’: No such fileor directory


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

[root@iZ25w7uckyyZ logs]# cd /etc
[root@iZ25w7uckyyZ etc]#  find /etc -perm -222 -ls
658871   0 lrwxrwxrwx   1 root    root           14 Jun 18 16:50/etc/sysctl.d/99-sysctl.conf -> ../sysctl.conf
658524   0 lrwxrwxrwx   1 root     root           59 Nov 21  2014/etc/fonts/conf.d/10-scale-bitmap-fonts.conf ->/usr/share/fontconfig/conf.avail/10-scale-bitmap-fonts.conf
658540   0 lrwxrwxrwx   1 root     root           50 Nov 21  2014 /etc/fonts/conf.d/90-synthetic.conf-> /usr/share/fontconfig/conf.avail/90-synthetic.conf
658525   0 lrwxrwxrwx   1 root     root           58 Nov 21  2014 /etc/fonts/conf.d/20-unhint-small-vera.conf-> /usr/share/fontconfig/conf.avail/20-unhint-small-vera.conf
658538   0 lrwxrwxrwx   1 root     root           48 Nov 21  2014 /etc/fonts/conf.d/69-unifont.conf ->/usr/share/fontconfig/conf.avail/69-unifont.conf

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

[root@iZ25w7uckyyZ etc]# find /etc -size+1M -a -type f -ls
791481 6824 -r--r--r--   1 root    root      6984832 Sep  5 15:10 /etc/udev/hwdb.bin
793843 3700 -rw-r--r--   1 root    root      3786319 Jun 18 16:51/etc/selinux/targeted/policy/policy.29
659990 1308 -rw-------   1 root    root      1335701 Jun 18 16:51/etc/selinux/targeted/contexts/files/file_contexts.bin


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

#find /etc/init.d/ -perm -113 –ls


12、查找/usr目錄下不屬於rootbinhadoop的文件;

#find /usr -not -user root -a -not -userbin –a  -not  -user hadoop


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

# find /etc  -not –perm 222


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

#find /etc/ -mtime -7 -a -not -user root -a-not -user hadoop



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