1、显示当前系统上root、fedora或user1用户的默认shell;
[root@zf ~]# grep -E "^(root|fedora)\>" /etc/passwd | cut -d: -f1,7 root:/bin/bash fedora:/bin/bash
2、找出/etc/rc.d/init.d/functions文件中某单词后面跟一组小括号的行,形如:hello();
[root@zf ~]# grep -E "[[: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() { 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@zf ~]# echo "/usr/local/nginx/sbin" | grep -E -o "\<[[:alnum:]]+/?$" sbin [root@zf ~]# echo "/usr/local/nginx/sbin" | grep -E "^/[[:alnum:]/]+/?" /usr/local/nginx/sbin
4、找出ifconfig命令结果中的1-255之间数字;
[root@zf ~]# ifconfig eth0 | grep -E -o "\<[1-9]\>|\<[1-9][0-9]\>|\<1[0-9][0-9]\>|\<2[0-4][0-9]\>|\<25[0-5]\>" 29 33 83 56 10 10 10 20 10 10 10 255 255 255 255 64 1 4 5 3 9
5、挑战题:写一个模式,能匹配合理的IP地址;
[root@zf tmp]# ifconfig | 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])\>" 10.10.10.30 10.4.2.3 127.0.0.1
6、挑战题:写一个模式,能匹配出所有的邮件地址;
[root@zf tmp]# cat mail_test 12457@qq.com w2R3@163.com Zhang.45e@mageedu.com zd_jdf@pa-jd.com eijm8@weij.com.cn fjhiu@fngy.net [root@zf tmp]# grep -E -o "\<[^[:space:]]*\>@\<[^[:space:]]*\>\.\<[^[:space:]]*\>" mail_test 12457@qq.com w2R3@163.com Zhang.45e@mageedu.com zd_jdf@pa-jd.com eijm8@weij.com.cn fjhiu@fngy.net
7、查找/var目录下属主为root,且属组为mail的所有文件或目录;
[root@zf ~]# find /var -user root -group mail /var/spool/mail /var/spool/mail/root
8、查找当前系统上没有属主或属组的文件; 进一步:查找当前系统上没有属主或属组,且最近3天内曾被访问过的文件或目录;
[root@zf ~]# find / \( -nouser -o -nogroup \) /var/spool/mail/mandriva /home/mandriva /home/mandriva/.gnome2 /home/mandriva/.bash_profile /home/mandriva/.bash_logout /home/mandriva/.bashrc /home/mandriva/.mozilla /home/mandriva/.mozilla/extensions /home/mandriva/.mozilla/plugins [root@zf ~]# find / \( -nouser -o -nogroup \) -a -atime -3 /var/spool/mail/mandriva /home/mandriva /home/mandriva/.gnome2 /home/mandriva/.mozilla /home/mandriva/.mozilla/extensions /home/mandriva/.mozilla/plugins
9、查找/etc目录下所有用户都有写权限的文件;
[root@zf ~]# find /etc/ -perm -222 /etc/rc1.d /etc/init.d /etc/rc0.d /etc/httpd/modules /etc/httpd/run /etc/httpd/logs ...
10、查找/etc目录下大于1M,且类型为普通文件的所有文件;
[root@zf ~]# find /etc/ -size +2M -a -type f /etc/selinux/targeted/policy/policy.24 /etc/selinux/targeted/modules/active/policy.kern
11、查找/etc/init.d/目录下,所有用户都有执行权限,且其它用户有写权限的文件;
[root@zf ~]# find /etc/init.d/ -perm -113
12、查找/usr目录下不属于root、bin或hadoop的文件;
[root@zf ~]# find /usr/ -not \( -user root -o -user bin -o -user hadoop \) /usr/local/nginx/scgi_temp /usr/local/nginx/proxy_temp /usr/local/nginx/fastcgi_temp /usr/local/nginx/fastcgi_temp/1 /usr/local/nginx/fastcgi_temp/1/00 /usr/local/nginx/client_body_temp /usr/local/nginx/uwsgi_temp /usr/libexec/abrt-action-install-debuginfo-to-abrt-cache
13、查找/etc/目录下至少有一类用户没有写权限的文件;
[root@zf ~]# find /etc/ -not -perm -222 /etc/ /etc/rwtab /etc/cron.deny /etc/dnsmasq.d /etc/.pwd.lock ...
14、查找/etc目录下最近一周内其内容被修改过,且不属于root或hadoop的文件;
[root@zf ~]# find /etc/ -mtime -7 -a -not \( -user root -o -user hadoop \) /etc/yum.conf.bak
原创文章,作者:Powercat,如若转载,请注明出处:http://www.178linux.com/64987
评论列表(1条)
写的很好,尤其是挑战题,排版也很漂亮,继续加油