1、顯示當前系統上root、fedora或user1用戶的默認shell;
演示:
[root@263821a05cd9 /]# grep -E “^(root|fedora|user1)\>” /etc/passwd
root:x:0:0:root:/root:/bin/bash
[root@263821a05cd9 /]# grep -E “^(root|fedora|user1)\>” /etc/passwd |cut -d: -f7
/bin/bash
2、找出/etc/rc.d/init.d/functions文件中某單詞后面跟一組小括號的行,形如:hello();
演示
[root@node ~]# grep -E -o “[[:alnum:]]+()” /etc/rc.d/init.d/functions
checkpid()
checkpids()
kill()
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@node ~]# basename /etc/sysconfig/
sysconfig
[root@node ~]# echo “/etc/sysconfig/” | grep -Eo “[^/]+/?$” | cut -d\/ -f1
sysconfig
[root@node ~]# basename /etc/fstab
fstab
[root@node ~]# echo “/etc/fstab” | grep -Eo “[^/]+/?$” | cut -d\/ -f1
fstab
4、找出ifconfig命令結果中的1-255之間數字;
命令
ifconfig | grep -Eo “\<([1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\>”
5、挑戰題:寫一個模式,能匹配合理的IP地址;
演示:
lc@Archlc [19:26:47] {~}
–>$ cat iptest.txt
223.129.46.238
255.255.255.0
127.0.0.1
3479.88.3.2
3.2.3.555
lc@Archlc [19:27:44] {~}
–>$ cat iptest.txt | grep -Eo “(\<([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\>.){3}(\<[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\>”
223.129.46.238
255.255.255.0
127.0.0.1
6、挑戰題:寫一個模式,能匹配出所有的郵件地址;
命令
根據這個網頁 的說明,該模式為:
“^([a-zA-Z0-9_-.+]+)@([a-zA-Z0-9_-.]+).([a-zA-Z]{2,5})$”
7、查找/var目錄下屬主為root,且屬組為mail的所有文件或目錄;
演示
[root@node ~]# find /var -user root -a -group mail -ls
33595998 0 drwxrwxr-x 2 root mail 84 Feb 25 13:08 /var/spool/mail
8、查找當前系統上沒有屬主或屬組的文件;進一步:查找當前系統上沒有屬主或屬組,且最近3天內曾被訪問過的文件或目錄;
命令
find / -nouser -o -nogroup -ls
find / ( -nouser -o -nogroup ) -atime -3 -ls
9、查找/etc目錄下所有用戶都有寫權限的文件;
命令
find /etc -perm -222 -type f -ls
10、查找/etc目錄下大于1M,且類型為普通文件的所有文件;
演示
[root@node ~]# find /etc -size +1M -type f
/etc/udev/hwdb.bin
/etc/selinux/targeted/contexts/files/file_contexts.bin
/etc/selinux/targeted/policy/policy.30
/etc/selinux/targeted/active/policy.kern
原創文章,作者:FSSlc,如若轉載,請注明出處:http://www.www58058.com/70514
親,4題是1-255之間的數字哦!