第五周着重练习扩展正则元字符及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

相关推荐

  • 记录Linux入门3天,每天的点点滴滴记录

        Linux 文件系统的特性:      1、文件名严格区分字符大小写      2、文件名可以使用除了 /  意外任意的字符,但不建议使用特殊字符      3、文件名长度不能超过255个字符     &nbsp…

    Linux干货 2017-05-21
  • Ansible的基础知识

    为什么要学习ansible:     ansible是自动化运维的一种工具,使用ansible可以一次性管理多台主机,为多台主机安装或这执行相同或者不同的操作,省去了一台台主机去重复执行相同的任务,可以使用corn选项结合本机的crontab设置本主机的任务性计划,比如,每天导出nginx的access.log和err…

    Linux干货 2016-11-03
  • 【福利贴-招聘】- python运维开发工程师

    职位描述  岗位职责: 1、负责公司CMDB的建设,包括资产管理、dns、工单系统、ngnix自动化、监控等的开发 2、帮助运维团队和业务团队提高自动化效率 3、维护和开发持续化集成环境; 4、负责公司运维系统的规划、选型、部署上线和日常维护管理工作; 5、负责CMDB团队的建设、管理和人才培养机制…

    Linux干货 2015-04-03
  • Bash的I/O重定向及管道

    每周更新的博客定时派送啦,本周与大家一起分享的是重定向和管道 首先了解一下 读入数据:Input 输出数据:Output 我们来看一下重定向:  >  覆盖重定向 上面图中 > 文件名     创建空文件 touch 文件名 创建空文件 这两种方法都可以创建一个新的文…

    2017-07-21
  • Nginx/LVS/HAProxy负载均衡软件优缺点总结

    Nginx/LVS/HAProxy简单介绍:   Nginx:专为性能优化而开发,性能是其最重要的考量,实现上非常注重效率 。它支持内核Poll模型,能经受高负载的考验,有报告表明能支持高达 50,000个并发连接数。 LVS:使用Linux内核集群实现一个高性能、高可用的负载均衡服务器,具有很好的可伸缩性(Scalability)、可靠性(Rel…

    2017-06-24
  • M22 Centos设置yum源方法

    实验目的: 使用虚拟机模拟建立yum源服务器,在客户机上指定yum源为该服务器。 实验器材: WMware12安装Centos6.8虚拟机作为yum服务源 WMware12安装Centos7.3 作为客户端访问yum源服务器 实验原理图: 实验过程: 服务器端: 1、  显示已经挂载的光盘 #cd /misc/cd #先执行此命令才可以看到光盘挂载…

    2017-03-06

评论列表(1条)

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

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