Find工具实例

 

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

        [root@localhost ~]# grep -E "^(root|fadora|user1)\>" /etc/passwd | cut -d : -f 1,7
        root:/bin/bash
        fadora:/bin/bash
        user1:/bin/bash

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

        [root@localhost ~]# grep -E -o "^[[:alnum:]]+\(\)" /etc/init.d/functions 
        checkpid()
        daemon()
        killproc()
        pidfileofproc()
        pidofproc()
        status()
        success()
        failure()
        passed()
        warning()
        action()
        strstr()

3、使用echo命令输出一个绝对路径,使用grep取出其基名。扩展取出其路径名

        [root@localhost ~]# echo /etc/init.d/functions | grep -E -o "[^/]+/?$"
        functions
    扩展:
        [root@localhost ~]# echo /etc/init.d/functions | grep -E -o "^/.+/"
        /etc/init.d/

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

        [root@localhost ~]# ifconfig | grep -E -o "\<([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-5][0-5])\>"

5、写一个模式,能匹配合理的IP地址。

        [root@localhost ~]# ifconfig | grep -E -o "\<[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\>"
        10.1.8.93
        255.255.255.0
        10.1.8.255
        127.0.0.1
        255.0.0.0
        192.168.122.1
        255.255.255.0
        192.168.122.255

6、写一个模式,能匹配出所有邮件地址。

        [root@localhost ~]# grep -E -o "[[:alnum:]]+[[:punct:]]?[[:alnum:]]+@[[:alnum:]]+\.[[:alnum:]]+"

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

        [root@localhost ~]# find /var/ -user root -group mail -ls
        134321240    4 drwxrwxr-x   2 root     mail         4096 11月 25 10:22 /var/spool/mail

8、查找当前系统上没有属主或属组的文件。

        [root@localhost ~]# find / \( -nouser -o -nogroup \) -ls
           135    0 drwx------   2 1005     1005           59 11月 12 01:20 /home/mandriva
           136    4 -rw-r--r--   1 1005     1005           18 11月 20  2015 /home/mandriva/.bash_logout
           137    4 -rw-r--r--   1 1005     1005          193 11月 20  2015 /home/mandriva/.bash_profile
           138    4 -rw-r--r--   1 1005     1005          231 11月 20  2015 /home/mandriva/.bashrc
        134677928    0 -rw-rw----   1 1005     mail            0 11月 12 01:20 /var/spool/mail/mandriva

8.1、查找当前系统上没有属主或属组,且最近3天内曾被访问过的文件或目录。

        [root@localhost ~]# find / \( -nouser -o -nogroup \) -atime -3 -ls
           135    0 drwx------   2 1005     1005           59 11月 12 01:20 /home/mandriva

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

        [root@localhost ~]# find /etc -perm -222 -type f -ls
        135034984    4 -rw-rw-rw-   1 root     root          541 11月 25 11:30 /etc/fstab1

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

        [root@localhost ~]# find /etc -size +1M -type f -exec ls -lh {} \;
        -r--r--r--. 1 root root 6.7M 11月 23 22:45 /etc/udev/hwdb.bin
        -rw-r--r--. 1 root root 3.7M 11月 21 2015 /etc/selinux/targeted/policy/policy.29
        -rw-r--r--. 1 root root 1.4M 3月   6 2015 /etc/brltty/zh-tw.ctb

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

        [root@localhost ~]# find /etc/init.d/ -perm -113 -type f -ls

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

        [root@localhost ~]# find /usr/ -not \( -user root -o -user bin -o -user hadoop \)  -type f -ls
        205959185   16 -rwsr-sr-x   1 abrt     abrt        15336 12月  1  2015 /usr/libexec/abrt-action-install-debuginfo-to-abrt-cache

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

        find /etc/ -not -perm -222 -type f -ls

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

        find /etc/ -mtime -7 -a -not \( -user root -o -user hadoop \) -type f -ls

 

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

(0)
641348038@qq.com641348038@qq.com
上一篇 2016-11-27 19:21
下一篇 2016-11-27 20:01

相关推荐

  • 脚本的进阶与一些基本脚本

    1,脚本中用于表示数字大小写和符号为: -gt(大于)-lt(小于)-ne(不等于)-eq(等于) 格式为 [[空格 ”符号”空格]] 2,测试文件类型的选项 -f(是否为普通文件)-l(是否为链接文件)-d(是否为目录)-e(单独测试文件是否存在) 3,if语句的格式:(其中path代表条件,elif链接多个条件,最后一个条件用else表示) if pat…

    Linux干货 2017-05-22
  • 方便实用的文件查找与压缩

    在平时的运维工作当中通常会编辑某些文件,但时间久了,突然一下子记不起文件的名字,遇到的事情又很紧急,需要立马去处理,而自己只知道那个文件部分的特征信息,我们需要在系统中去搜索自己想要的文件,那么有没有办法去实现呢,当然有,在我们的系统中,文件查找的工具有两个,locate和find。那么下面来介绍这两个工具的用法以及两个工具之间的差别。 在我们linux系统…

    Linux干货 2016-08-13
  • Linux系统上的文件处理工具

    Linux系统上的文件处理工具 我们都知道在计算机中,存在大量的文件,这些文件中包含大量的信息。可是有些时候,为了工作的效率,我们在茫茫信息中提取出我们所需要的信息,这样的技能就显得尤为重要。Linux系统上为我我们提供了多种多样的文本处理工具,下面我们来简单说一下。 查看文件内容我们可以使用less命令,cat命令,more命令等等 cat cat [OP…

    Linux干货 2016-08-05
  • 文本处理-三剑客-sed

    处理、编辑文本文件
    [option]… ‘script’ inputfile…

    2018-03-13
  • MAN手册、Linux文件系统等介绍

    适合人群:Linux初学者 主要内容: Man手册使用介绍        FHS文件系统介绍        Linux文件类型介绍        随堂笔记 操作环境:CentOs 6.8 ☆ MAN 手册介绍 man手册…

    Linux干货 2016-10-18
  • MariaDB之MHA配置

    工作拓扑 一、MHA简明:     MHA(Master HA)是一款开源的MySQL的高可用程序,它为MySQL主从复制架构提供了    automating master failover 功能。MHA在监控到master节点故障时,会提升其中    拥有最新数据的…

    2017-01-01

评论列表(1条)

  • luoweiro
    luoweiro 2016-11-30 23:33

    作业总结的非常棒,详细的过程,要是有一些拓展知识就更好了。