1、显示当前系统上root、fedora或user1用户的默认shell;
[root@centos ~]# egrep '^(root|fedora|user1)\>' /etc/passwd |cut-d: -f1,7
root:/bin/bash
fedora:/bin/bash
user1:/bin/bash
2、找出/etc/rc.d/init.d/functions文件中某单词后面跟一组小括号的行,形如:hello();
[root@centos ~]#grep -o ".*()" /etc/rc.d/init.d/functions
或
[root@centos ~]#egrep -o ".*\(\)" /etc/rc.d/init.d/functions
systemctl_redirect ()
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取出其基名;扩展:取出其路径名
1)取基名
[root@centos ~]# echo"/etc/sysconfig/network-scripts/ifcfg-eno16777736" |grep -E -o" [^/]+/?$" | cut -d"/" -f1
ifcfg-eno16777736
2)扩展:取路径名
[root@centos~]# echo "/etc/sysconfig/network-scripts/ifcfg-eno16777736" |grep -E-o "/.*/" |grep -o /.*[^/]
/etc/sysconfig/network-scripts
4、找出ifconfig命令结果中的1-255之间数字;、
[root@centos ~]# ifconfig |egrep "(\<[1-9]\>|\<[1-9][0-9]\>|\<1[0-9]{2}\>|\<2[0-5]{2}\>)"
5、挑战题:写一个模式,能匹配合理的IP地址;
首先合理的IP地址为:0.0.0.0----255.255.255.255区间的所有IP,所以匹配的模式为:
[root@centos~]#ifconfig|egrep"(\<[0-9]\>|\<[1-9][0-9]\>|\<1[0-9]{2}\>|\<2[0-5]{2}\>)"."(\<[0-9]\>|\<[1-9][0-9]\>|\<1[0-9]{2}\>|\<2[0-5]{2}\>)"."(\<[0-9]\>|\<[1-9][0-9]\>|\<1[0-9]{2}\>|\<2[0-5]{2}\>)"."(\<[0-9]\>|\<[1-9][0-9]\>|\<1[0-9]{2}\>|\<2[0-5]{2}\>)"
6、挑战题:写一个模式,能匹配出所有的邮件地址;
[root@centos~]# cat 1.txt | grep "[[:alnum:]]\+@[[:alnum:]]\+.com"
1112@qq.com
abc@163.com
zhangsan@hotmail.com
lj@szgwnet.com
7、查找/var目录下属主为root,且属组为mail的所有文件或目录;
[root@centos bin]# find /var -user root-group mail
/var/spool/mail
8、查找当前系统上没有属主或属组的文件;进一步:查找当前系统上没有属主或属组,且最近3天内曾被访问过的文件或目录;
没有属主或属组的文件
[root@centos bin]# find / -nouser -o-nogroup
/home/mandrive
/home/mandrive/.mozilla
/home/mandrive/.mozilla/extensions
/home/mandrive/.mozilla/plugins
/home/mandrive/.bash_logout
/home/mandrive/.bash_profile
/home/mandrive/.bashrc
/var/spool/mail/mandrive
且最近3天内曾被访问过的文件或目录
[root@centos bin]# find / -nouser -o-nogroup -a -atime -3
/home/mandrive
/home/mandrive/.mozilla
/home/mandrive/.mozilla/extensions
/home/mandrive/.mozilla/plugins
/home/mandrive/.bash_logout
/home/mandrive/.bash_profile
/home/mandrive/.bashrc
9、查找/etc目录下所有用户都有写权限的文件;
[root@centos bin]# find /etc -perm -222
/etc/mtab
/etc/fonts/conf.d/66-sil-abyssinica.conf
etc/fonts/conf.d/59-liberation-mono.conf
/etc/fonts/conf.d/65-0-lohit-tamil.conf
/etc/fonts/conf.d/59-liberation-sans.conf
/etc/fonts/conf.d/66-ucs-miscfixed.conf
/etc/fonts/conf.d/10-scale-bitmap-fonts.conf
/etc/fonts/conf.d/65-0-jomolhari.conf
/etc/fonts/conf.d/20-unhint-small-vera.conf
/etc/fonts/conf.d/57-paratype-pt-sans.conf
/etc/fonts/conf.d/66-sil-nuosu.conf
/etc/fonts/conf.d/25-unhint-nonlatin.conf
/etc/fonts/conf.d/65-0-khmeros-base.conf
/etc/fonts/conf.d/30-metric-aliases.conf
/etc/fonts/conf.d/30-urw-aliases.conf
10、查找/etc目录下大于1M,且类型为普通文件的所有文件;
[root@centos bin]# find /etc -size +1M-type f -ls
2196162 3772 -rw-r--r-- 1 root root 3858924 11月 21 2015 /etc/selinux/targeted/policy/policy.29
67108998 6852 -r--r--r-- 1 root root 7014922 7月 9 06:20 /etc/udev/hwdb.bin
1085866 1336 -rw-r--r-- 1 root root 1367395 3月 6 2015/etc/brltty/zh-tw.ctb
11、查找/etc/init.d/目录下,所有用户都有执行权限,且其它用户有写权限的文件;
[root@centos bin]# find /etc/init.d/ -perm-113
12、查找/usr目录下不属于root、bin或hadoop的文件;
[root@centos bin]# find /usr -not \( -userroot -o -user bin -o -user hadoop \)
/usr/share/polkit-1/rules.d
/usr/libexec/abrt-action-install-debuginfo-to-abrt-cache
13、查找/etc/目录下至少有一类用户没有写权限的文件;
[root@centos bin]#find /etc/ -not -perm -222 -ls |head
134313217 12 drwxr-xr-x 129 root root 8192 9月 4 00:35 /etc/
134313218 4 -rw-r--r-- 1 root root 541 7月 9 05:52 /etc/fstab
134313219 0 -rw------- 1 root root 0 7月 9 05:52 /etc/crypttab
137513730 4 -rw-r--r-- 1 root root 101 9月 4 00:35 /etc/resolv.conf
201326731 0 drwxr-xr-x 3 root root 36 7月 9 05:54 /etc/fonts
148 8 drwxr-xr-x 2 root root 4096 7月 9 06:07 /etc/fonts/conf.d
255055 4 -rw-r--r-- 1 root root 1160 1月 25 2014 /etc/fonts/conf.d/25-no-bitmap-fedora.conf
255070 4 -rw-r--r-- 1 root root 978 8月 31 2013 /etc/fonts/conf.d/README
201845899 8 -rw-r--r-- 1 root root 5582 6月 10 2014 /etc/fonts/fonts.conf
67109027 0 drwxr-xr-x 6 root root 97 7月 9 06:00 /etc/X11
14、查找/etc目录下最近一周内其内容被修改过,且不属于root或hadoop的文件;
[root@centos bin]# find /etc -mtime -7 -a-not \( -user root -o -user hadoop \)
或
[root@centos bin]# find /etc -mtime -7 -a-not -user root -a -not -user hadoop
|