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
下一篇 2016-11-27

相关推荐

  • Linux磁盘管理实操

    Linux磁盘管理实操 1、创建一个10G分区,并格式为ext4文件系统。 先使用fdisk工具创建一个10G的新分区。使用fdisk打开要创建磁盘分区的物理设备fdisk /dev/sdb,然后使用n指令创建新的分区,分区类型选此处选择为主分区,第一个柱面使用默认的1,最后的柱面,使用+10G这种表示方式,表示创建的分区大小为10G。 创建后可以使用p指令…

    系统运维 2016-12-13
  • N25 – Week 5 blog

    1. 显示当前系统上root, fedora或user1用户的默认shell [root@dhcp-10-129-6-166 ~]# grep -E "root|fedora|user1" /etc/passwd | grep -o "[^…

    Linux干货 2016-12-27
  • RAID各级别的特性及使用介绍(8.3博客作业)

    RAID各级别的特性及使用介绍 介绍: 独立硬盘冗余阵列(RAID:Redundant Array of Independent Disks),旧称廉价磁盘冗余阵列,简称磁盘阵列。 组成: 多块磁盘,RAID控制器(硬件RAID、软件RAID)     硬件RAID:自带CPU的RAID卡,不消耗服务器资源,可通过备份…

    Linux干货 2016-07-16
  • N25-第八周博客作业

    1、写一个脚本,使用ping命令探测172.16.250.1-172.16.250.254之间的所有主机的在线状态; 在线的主机使用绿色显示;不在线的主使用红色显示; #!/bin/bash # ping探测主机在线状态 for i in `seq 254`;do if ping -c 1 172.16.0.$i &> /dev/null;th…

    Linux干货 2017-02-23
  • 网络中多网卡和多ip中的高可用

    一、虚拟网卡实现一个网卡多个地址 1、单个网卡实现多个ipv4地址,只需要在该网卡的配置文件的目录新增网卡配置文件即可。进入网卡"eth0"的目录下 2、新增网卡配置文件"ifcfg-eth0:0"和"ifcfg-eth0:1" 3、关掉NetworkManager服务 4、重启网卡,让系统重读配置…

    Linux干货 2016-09-10
  • shell脚本之选择与执行

    流程控制  过程式编程语言: 顺序执行 选择执行 循环执行 选择执行:if语句  注意:if语句可嵌套  单分支 if 判断条件:then 条件为真的分支代码 fi  双分支 if 判断条件; then 条件为真的分支代码 else 条件为假的分支代码 fi 多分支 if…

    Linux干货 2016-09-19

评论列表(1条)

  • luoweiro
    luoweiro 2016-11-30 23:33

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