1、顯示當前系統上root、fedora或user1用戶的默認shell
[root@EASTED ~]# grep -E "(root|fedora|user1)" /etc/passwd root:x:0:0:root:/root:/bin/bash operator:x:11:0:operator:/root:/sbin/nologin fedora:x:1013:1013::/home/fedora:/bin/bash user1:x:1014:1014::/home/user1:/bin/bash [root@EASTED ~]# grep -E "(root|fedora|user1)" /etc/passwd|cut -d: -f7 /bin/bash /sbin/nologin /bin/bash /bin/bash
2、找出/etc/rc.d/init.d/functions文件中某單詞后面跟一組小括號的行,形如:hello();
[root@EASTED ~]# grep -E -o "[_[:alnum:]]+\(\)" /etc/rc.d/init.d/functions checkpid() __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() strstr() is_ignored_file() is_true() is_false() apply_sysctl()
3、使用echo命令輸出一個絕對路徑,使用grep取出基名;擴展:取出路徑名:
[root@aio2 ~]# echo /etc/sysconfig/network-scripts/ifcfg-eno1 | grep "[^\/]\+\/\?$" /etc/sysconfig/network-scripts/ifcfg-eno1
4、找出ifconfig命令結果中的1-255之間的數字;
[root@EASTED ~]# ifconfig | grep -E -o "\<([1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\>" 192 168 7 13 255 255 255 192 168 7 255 64 29 22 6 8 2 3 73 127 1 255 1 128 22 1 7 22 1 7 192 168 122 1 255 255 255 192 168 122 255 52 54 17 54
5、挑戰題:寫一個模式,能匹配合理的IP地址;
[root@aio2 ~]# ip addr list | grep -E -o "\<((1?[0-9][0-9]?|2[0-4][0-9]|25[0-4])\.){3}(1?[0-9][0-9]?|2[0-4][0-9]|25[0-4])\>" 127.0.0.1 10.10.139.12
6、挑戰題:寫一個模式,能匹配所有的郵件地址;
[root@aio2 ~]# grep -E "[^[:space:]].*@[^[:space:]].*" mail
7、查找/var目錄下屬主為root,且屬組為mail的所有文件和目錄;
[root@EASTED ~]# find /var -user root -a -group mail -ls 100664302 4 drwxrwxr-x 2 root mail 4096 1月 2 23:13 /var/spool/mail 103173137 4 -rw------- 1 root mail 661 1月 2 12:37 /var/spool/mail/root
8、查找當前系統上沒有屬主和屬組的文件;進一步查找當前系統上沒有屬主和屬組,且最近3天內曾被訪問過的文件或目錄;
[root@EASTED ~]# find / -nouser -a -nogroup -a -atime -3 find: ‘/proc/26189’: 沒有那個文件或目錄 find: ‘/proc/26379’: 沒有那個文件或目錄 find: ‘/proc/26380/task/26380/fd/6’: 沒有那個文件或目錄 find: ‘/proc/26380/task/26380/fdinfo/6’: 沒有那個文件或目錄 find: ‘/proc/26380/fd/6’: 沒有那個文件或目錄 find: ‘/proc/26380/fdinfo/6’: 沒有那個文件或目錄 find: ‘/run/user/1000/gvfs’: 權限不夠 /home/bash /home/bash/.mozilla /home/bash/.mozilla/extensions /home/bash/.mozilla/plugins /home/bash/.bash_logout /home/bash/.bash_profile /home/bash/.bashrc /home/testbash /home/testbash/.mozilla /home/testbash/.mozilla/extensions /home/testbash/.mozilla/plugins /home/testbash/.bash_logout /home/testbash/.bash_profile /home/testbash/.bashrc /home/basher /home/basher/.mozilla /home/basher/.mozilla/extensions /home/basher/.mozilla/plugins /home/basher/.bash_logout /home/basher/.bash_profile /home/basher/.bashrc /home/nologin /home/nologin/.mozilla /home/nologin/.mozilla/extensions /home/nologin/.mozilla/plugins /home/nologin/.bash_logout /home/nologin/.bash_profile /home/nologin/.bashrc
9、查找/etc/目錄下所有用戶都有寫權限的文件;
[root@EASTED ~]# find /etc -perm /222 -type f -ls
10、查找/etc目錄下大于1M,且類型為普通文件的所有文件;
[root@EASTED ~]# find /etc -size +1M -type f -exec ls -lh {} \; -rw-r--r--. 1 root root 3.7M 11月 21 2015 /etc/selinux/targeted/policy/policy.29 -r--r--r--. 1 root root 6.7M 8月 31 22:36 /etc/udev/hwdb.bin -rw-r--r--. 1 root root 1.4M 3月 6 2015 /etc/brltty/zh-tw.ctb
11、查找/etc/init.d/目錄下,所有用戶都有執行權限,且其它用戶都有寫權限的文件;
[root@EASTED ~]# find /etc/init.d -perm 113 -type f -ls
12、查找/usr目錄下不屬于root、bin或hadoop的文件;[root@EASTED ~]# find /usr -not ( -user
root -o -user bin \) -ls 68670714 4 drwx------ 2 polkitd root 4096 8月 31 22:24 /usr/share/polkit-1/rules.d 34502454 16 -rwsr-sr-x 1 abrt abrt 15336 12月 1 2015 /usr/libexec/abrt-action-install-debuginfo-to-abrt-cache
13、查找/etc/目錄下至少有一類用戶沒有寫權限的文件;
[root@EASTED ~]# find /etc -perm /222 -type f -ls
14、查找/etc/目錄下最近一周內其內容被修改過,且不屬于root或hadoop的文件;
[root@EASTED ~]# find /etc -mtime -7 -a -not -user root -a -not -user hadoop -ls
原創文章,作者:LYF,如若轉載,請注明出處:http://www.www58058.com/66355
寫的很好,排版也很漂亮,繼續加油