1、显示当前系统上root、fedora或user1用户的默认shell
[root@EASTED ~]# grep -E "(root|fedora|user1)" /etc/passwdroot: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/functionscheckpid()
__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:]].*" mail7、查找/var目录下属主为root,且属组为mail的所有文件和目录;
[root@EASTED ~]# find /var -user root -a -group mail -ls100664302 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 -3find: ‘/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 -ls10、查找/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 \) -ls68670714 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 -ls14、查找/etc/目录下最近一周内其内容被修改过,且不属于root或hadoop的文件;
[root@EASTED ~]# find /etc -mtime -7 -a -not -user root -a -not -user hadoop -ls