1、顯示當前系統上root、fedora或user1用戶的默認shell;
[root@rhel677850 ~]# grep "^\(root\|fedora\|user1\)" /etc/passwd|awk -F: '{print $1,$7}' root /bin/bash [root@rhel677850 ~]# egrep "^(root|fedora|user1)" /etc/passwd|awk -F: '{print $1,$7}' root /bin/bash
2、找出/etc/rc.d/init.d/functions文件中某單詞后面跟一組小括號的行,形如:hello();
[root@rhel677850 ~]# egrep "[[:alpha:]]+\(\)" /etc/rc.d/init.d/functions fstab_decode_str() { checkpid() { __readlink() { __fgrep() { __umount_loop() { __umount_loopback_loop() { __pids_var_run() { __pids_pidof() { daemon() { killproc() { pidfileofproc() { pidofproc() { status() { echo_success() { echo_failure() { echo_passed() { echo_warning() { update_boot_stage() { success() { failure() { passed() { warning() { action() { action_silent() { strstr() { confirm() { get_numeric_dev() { is_ignored_file() { is_true() { is_false() { apply_sysctl() { key_is_random() { find_crypto_mount_point() { init_crypto() {
3、使用echo命令輸出一個絕對路徑,使用grep取出其基名;
[root@rhel677850 ~]# echo "/etc/passwd"|grep -o "[^/]\+$" passwd 使用grep取路徑名 [root@rhel677850 ~]# echo "/etc/passwd"|grep -o ".*/" /etc/
4、找出ifconfig命令結果中的1-255之間數字;
[root@rhel677850 ~]# ifconfig | egrep -o "\<([1-9]|[1-9][0-9]|1[0-9][0-9]|[2[0-4][0-9]|25[0-5]])\>"
5、挑戰題:寫一個模式,能匹配合理的IP地址;
[root@rhel677850 ~]# 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]])\>" 10.31.78.50
6、挑戰題:寫一個模式,能匹配出所有的郵件地址;
[root@rhel677850 ~]# egrep "[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$" mail.txt zhangxialoa@mageedu.com 318810@qq.com
7、查找/var目錄下屬主為root,且屬組為mail的所有文件或目錄;
[root@rhel677850 ~]# ls -l /var | awk '/\<root mail\>/{print $NF}'
8、查找當前系統上沒有屬主或屬組的文件;
[root@rhel677850 ~]# find / -nouser -a -nogroup
進一步:查找當前系統上沒有屬主或屬組,且最近3天內曾被訪問過的文件或目錄;
[root@rhel677850 ~]# find / -nouser -a -nogroup
9、查找/etc目錄下所有用戶都有寫權限的文件;
[root@rhel677850 ~]# find / -perm -222
10、查找/etc目錄下大于1M,且類型為普通文件的所有文件;
[root@rhel677850 ~]# find /etc/ -size +1M -type f /etc/pki/tls/certs/ca-bundle.trust.crt /etc/selinux/targeted/modules/active/policy.kern /etc/selinux/targeted/policy/policy.24 /etc/gconf/gconf.xml.defaults/%gconf-tree.xml
11、查找/etc/init.d/目錄下,所有用戶都有執行權限,且其它用戶有寫權限的文件;
[root@rhel677850 ~]# find /etc/init.d -perm -113 /etc/init.d
12、查找/usr目錄下不屬于root、bin或hadoop的文件;
[root@rhel677850 ~]# find /usr/ -not \( -user root -o -user bin -o -user hadoop \)
13、查找/etc/目錄下至少有一類用戶沒有寫權限的文件;
[root@rhel677850 ~]# find /etc/ -not -perm -222
14、查找/etc目錄下最近一周內其內容被修改過,且不屬于root或hadoop的文件;
[root@rhel677850 ~]# find /etc/ -mtime -7 -not \( -user root -o -user hadoop \)
原創文章,作者:zhangxiaola,如若轉載,請注明出處:http://www.www58058.com/47831
寫的很好,看的出來很用心,不過還是要注意排版的問題,希望繼續保持