第五周着重练习扩展正则元字符及find命令

1、显示当前系统上root、fedora或user1用户的默认shell;

grep -E "^(root|hadoop|user1)\>" /etc/passwd |cut -d":" -f1,7

2、找出/etc/rc.d/init.d/functions文件中某单词后面跟一组小括号的行,形如:hello();

    [root@centos7 /]# 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@centos7 /]#  echo "/etc/rc.d/init.d/functions" |grep -E -o "[^/]+$"
functions

[root@centos7 /]#  echo "/etc/rc.d/init.d/functions" |grep -E -o  "^/.*/"
/etc/rc.d/init.d/

4、找出ifconfig命令结果中的1-255之间数字;

ifconfig | grep  -E  -o  "\<([1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\>"

5、挑战题:写一个模式,能匹配合理的IP地址;

grep -E -o "\<([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\>.\<([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\>.\<([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\>.\<([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\>"

6、挑战题:写一个模式,能匹配出所有的邮件地址;

grep -E -o “\<[a-z0-9A-Z._%+-]+@[a-z0-9A-Z.-]+\.[a-zA-Z]{2,6}\>”

7、查找/var目录下属主为root,且属组为mail的所有文件或目录;

[root@centos7 /]# find /var/ -user root -a -group mail
/var/spool/mail
/var/spool/mail/root

8、查找当前系统上没有属主或属组的文件;进一步:查找当前系统上没有属主或属组,且最近3天内曾被访问过的文件或目录;

find / -nouser -o -nogroup -atime 3

9、查找/etc目录下所有用户都有写权限的文件;

find /etc/ -perm -020

10、查找/etc目录下大于1M,且类型为普通文件的所有文件;

find /etc/ -size +1M -type f

11、查找/etc/init.d/目录下,所有用户都有执行权限,且其它用户有写权限的文件;

find /etc/init.d/ -perm -111 -perm -002

12、查找/usr目录下不属于root、bin或hadoop的文件;

[root@centos7 /]# find /usr ! \( -user root -o -user bin -o -user hadoop \)
/usr/share/polkit-1/rules.d
/usr/libexec/abrt-action-install-debuginfo-to-abrt-cache

13、查找/etc/目录下至少有一类用户没有写权限的文件;

[root@centos7 /]# find /usr ! \( -user root -o -user bin -o -user hadoop \)
/usr/share/polkit-1/rules.d
/usr/libexec/abrt-action-install-debuginfo-to-abrt-cache
[root@centos7 /]# find /usr -not \( -user root -o -user bin -o -user hadoop \)
/usr/share/polkit-1/rules.d
/usr/libexec/abrt-action-install-debuginfo-to-abrt-cache
[root@centos7 /]# find /usr ! \( -user root -o -user bin -o -user hadoop \)
/usr/share/polkit-1/rules.d
/usr/libexec/abrt-action-install-debuginfo-to-abrt-cache
[root@centos7 /]# find /etc/ -not -perm /222
/etc/pki/ca-trust/extracted/java/cacerts
/etc/pki/ca-trust/extracted/openssl/ca-bundle.trust.crt
/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem
/etc/pki/ca-trust/extracted/pem/email-ca-bundle.pem
/etc/pki/ca-trust/extracted/pem/objsign-ca-bundle.pem
/etc/gshadow
/etc/openldap/certs/password
/etc/shadow
/etc/ld.so.conf.d/kernel-3.10.0-327.el7.x86_64.conf
/etc/ld.so.conf.d/kernel-3.10.0-327.36.3.el7.x86_64.conf
/etc/udev/hwdb.bin
/etc/gshadow-
/etc/dbus-1/system.d/cups.conf
/etc/shadow-
/etc/lvm/profile/cache-mq.profile
/etc/lvm/profile/cache-smq.profile
/etc/lvm/profile/command_profile_template.profile
/etc/lvm/profile/metadata_profile_template.profile
/etc/lvm/profile/thin-generic.profile
/etc/lvm/profile/thin-performance.profile
/etc/pam.d/cups
/etc/machine-id
/etc/sudoers

14、查找/etc目录下最近一周内其内容被修改过,且不属于root或hadoop的文件;

find /etc -mtime -7 ! \( -user root -o -user hadoop \)

原创文章,作者:N24_Jerry,如若转载,请注明出处:http://www.178linux.com/63597

(0)
N24_JerryN24_Jerry
上一篇 2016-12-13 12:29
下一篇 2016-12-13 14:09

相关推荐

  •   在服务器托管的过程中出现故障是不能完全避免的问题,可能是服务器硬盘出现硬件故障或者是防火墙遭到攻击。那么服务器托管出现故障怎么办?

      在服务器托管的过程中出现故障是不能完全避免的问题,可能是服务器硬盘出现硬件故障或者是防火墙遭到攻击。那么服务器托管出现故障怎么办?   服务器硬盘出现硬件故障时,大家应注意以下几点:   1、硬盘出现异声,此时磁头已不正常寻址,为防止打伤盘体,需立即断电不可拆解硬盘,需交有超净间的专业公司拆开检查。   2、BIOS不认盘,找不到硬盘,先请计算机工程师仔…

    Linux干货 2016-04-05
  • Mysql备份I

    Mysql备份I I备份在什么时候会被需要 硬件故障 机器无法启动 机器突然消失了怎么办 业务出现异常 一定要先select 在操作 类似drop或delete的操作 攻击 程序bug 业务特殊需求  重要数据多处多次多版本备份 至少有2份远程备份文件2处本地备份 II哪些东西需…

    Linux干货 2016-06-09
  • tcpdump诊断nginx问题

    自从上级公司离职后,快一年的时间没有写php程序和搭建LNMP环境,一直在做db运维和运维工具开发方面的事情。 最近决定开发开发一些自动话方面工具,重新拾起php,于是在测试机上搭建一个LNMP环境。 1、 nginx 404错误 一般的出现404错误,找不到页面资源。首先用strace排除了存在文件访问权限的问题,其次nginx的root参数设置也没有任何…

    Linux干货 2016-05-03
  • 安装CentOS 6.9与CentOS7.3

    今天学习了如何安装CentOS6.9与CentOS7.3. 安装CentOS6.9 首先打开虚拟机如下如所示: 然后点击创建新的虚拟机: 选择典型,然后点击下一步: 一般会选择稍后安装操作系统,然后点击下一步 客户机操作系统有很多,因为今天只安装CentOS 所以选择Linux 版本则选择CentOS 64 位 (因为CentOS7以上没有32位版本,只有C…

    2017-07-14
  • 电子眼find

     1、摩根定律。         话不多说,先上图。          如图:A和B交集为3    A = 4 + 3  &nbs…

    Linux干货 2016-08-16
  • Linux入门命令(一)

    已经一年没有在接触过Linux了,经过一个星期的Linux学习之后,又重新对她产生了兴趣,本周学习了一些Linux入门级的命令: (1)     (1)tty 这个命令是查看当前所处于的中终端信息的,同样也可以使用 who am i ,who以及w来查看终端信息. 终端也还有物理终端、虚拟终端以及伪终端之分,在虚拟机下…

    2017-07-16

评论列表(1条)

  • 马哥教育
    马哥教育 2016-12-23 00:48

    赞~几个例子都不错,继续加油~