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

 

原创文章,作者:[email protected],如若转载,请注明出处:http://www.178linux.com/60726

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

相关推荐

  • Linux文件权限之facl

    1、什么是facl         facl(file access control list)文件访问控制列表,主要目的是在原有的u,g,o之外,另一层让普通用户能控制赋权给另外的用户或组的机制;       &nbs…

    Linux干货 2016-09-19
  • N21_第8周_网络

    N21_第8周_网络 作业题目: 1、请描述网桥、集线器、二层交换机、三层交换机、路由器的功能、使用场景与区别。     网桥:(Bridge)也称桥接器,是连接两个局域网的存储转发设备,用它可以完成具有相同或相似体系结构网络系统的连接。       &nbs…

    Linux干货 2016-10-09
  • rpm详解

    rpm详解 rpm详解 rpm使用方法 rpm起源 rpm是什么 rpm命名格式 rpm优缺点 rpm获取注意 rpm命令使用 rpm起源  由于在linux中安装应用程序需要源码包编译安装,对于非专业人员而言难度太大,因而出现一种将源码编译好的二进制程序,库文件,配置文件,帮助文件等打包成一个或多个特定格式的程序包,而管理这类包的工具之一,则称为…

    Linux干货 2016-12-23
  • Nginx浅谈(一)

    浅谈nginx(一) 此文主要介绍nginx的基础知识及其基本配置,一为巩固,二为记录 知识点: nginx的作用 nginx的基本配置框架 nginx一些常用模块介绍 1、什么是nginx     nginx是一款免费的,开源的,高性能的HTTP服务软件,它不仅能     够支…

    Linux干货 2017-01-15
  • 修复引导启动

    修复MBR 备份MBR: dd if=/dev/sda of=/root/mbr.bak  bs=1  count=512  破坏 dd if=/dev/zero of=/dev/sda  bs=1 count=446 这里只要小于等于446即可。 借助安装光盘修复 装入光盘,在光盘引导界面选择 然后全部默认进入救援命令界面 切换根目录 使用grub-ins…

    2017-12-24
  • N22-第3周作业-冥界之王

    1、列出当前系统上所有已经登录的用户的用户名,注意:同一个用户登录多次,则只显示一次即可。 [root@CentOS6 ~]# who  | cut -d " " -f1 | uniq 2、取出最后登录到当前系统的用户的相关信息。…

    Linux干货 2016-09-19

评论列表(1条)

  • luoweiro
    luoweiro 2016-11-30 23:33

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