zoukankan      html  css  js  c++  java
  • 35个例子学会find

    find的使用格式如下:

      $ find <指定目录> <指定条件> <指定动作>

      - <指定目录>: 所要搜索的目录及其所有子目录。默认为当前目录。

      - <指定条件>: 所要搜索的文件的特征。

      - <指定动作>: 对搜索结果进行特定的处理。

    如果什么参数也不加,find默认搜索当前目录及其子目录,并且不过滤任何结果(也就是返回所有文件),将它们全都显示在屏幕上。

    1.当前目录下查找文件

    [root@miyan ~]# find . -name test.txt 
    ./findtest/test.txt

    2.指定目录下查找

    [root@miyan ~]# find /root/ -name test.txt
    /root/findtest/test.txt

    3.忽略大小写查找

    [root@miyan ~]# find /root -iname test.txt
    /root/findtest/test.txt
    /root/findtest/TEST.txt

    4.查找目录

    [root@miyan ~]# find / -type d -name test
    /usr/lib64/python2.7/unittest/test
    /usr/lib64/python2.7/test
    /usr/src/kernels/3.10.0-229.14.1.el7.x86_64/include/config/test
    /usr/src/kernels/3.10.0-229.14.1.el7.x86_64/lib/raid6/test

    5.按名称查找php文件

    [root@miyan zabbix]# find . -type f -name events.php 
    ./events.php

    6.在目录中查找所有的php文件

    [root@miyan zabbix]# find . -type f -name "*.php"
    ./graphs.php
    ./tr_logform.php
    ./authentication.php
    ./popup_httpstep.php
    ./image.php
    ..........

    7.查找文件权限是777的

    [root@miyan ~]# find . -type f -perm 0777 -print
    ./findtest/test.txt

    8.查找文件权限不是777的

    [root@miyan ~]# find . -type f ! -perm 0777 -print

    9.查找644权限的SGID文件

    [root@miyan ~]# find / -perm 2644

    10.查找权限为551的粘着位文件

    [root@miyan ~]# find / -perm 1551

    11.查找所有SUID文件

    root@miyan ~]# find / -perm /u=s

    12.查找所有SGID文件

    [root@miyan ~]# find / -perm /g+s

    13.查找所有只读文件

    [root@miyan ~]# find / -perm /u=r

    14.查找所有可执行文件

    [root@miyan ~]# find / -perm /a=x

    15.查找所有777文件,并改为644

    反斜杠用来告诉find何时命令结束

    [root@miyan ~]# find / -type f -perm 0777 -print -exec chmod 644 {} ;

    16.查找所有777的目录,并改为755

    [root@miyan ~]# find / -type d -perm 777 -print -exec chmod 755 {} ;

    17.查找并删除某个文件

    [root@miyan ~]# find . -type f -name "test.txt" -exec rm -f {} ;

    18.查找并删除多个文件

    [root@miyan ~]# find . -type f -name "*.txt" -exec rm -f {} ;

    19.查找所有的空文件

    [root@miyan ~]# find /tmp -type f -empty

    20.查找所有空目录

    [root@miyan ~]# find /tmp -type d -empty

    21.查找所有隐藏文件

    [root@miyan ~]# find /tmp -type f -name ".*"

    22.根据用户查找某个文件

    [root@miyan ~]# find / -user root -name test.txt

    23.根据用户查找所有的文件

    在/home下属于某个用户的所有文件

    [root@miyan ~]# find /home -user zabbix
    /home/zabbix
    /home/zabbix/.bash_history
    /home/zabbix/.config
    /home/zabbix/.config/abrt
    /home/zabbix/mysql-community-release-el7-5.noarch.rpm
    /home/zabbix/.lesshst
    /home/zabbix/.cache
    /home/zabbix/.cache/abrt
    /home/zabbix/.cache/abrt/lastnotification
    /home/zabbix/.bash_logout
    /home/zabbix/.viminfo
    /home/zabbix/.mysql_history
    /home/zabbix/.bashrc
    /home/zabbix/.bash_profile

    24./home目录下查找某个组的所有文件

    [root@miyan ~]# find /home -group developer

    25./home目录下忽略大小写查找用户zabbix的所有文件

    [root@miyan ~]# find /home -user zabbix -iname "*.txt"

    26.查找50天之内修改过的文件

    [root@miyan ~]# find / -mtime 50

    27.查找50天之内被存取过的文件

    [root@miyan ~]# find / -atime 50

    28.查找50-100天之内修改过的文件

    [root@miyan ~]# find / -atime +50 -mtime -100

    29.查找1个小时之内有变化的文件

    [root@miyan ~]# find / -cmin -60

    30.查找1个小时之内修改过的文件

    [root@miyan ~]# find / -mmin -60

    31.查找1个小时之内被存取过的文件

    [root@miyan ~]# find / -amin -60

    32.查找所有的50M大小的文件

    [root@miyan ~]# find / -size 50M

    33.查找50-100M之间的文件

    [root@miyan ~]# find / -size +50M -size -100M

    34.查找并删除100M大小的文件

    [root@miyan ~]# find / -size +100M -exec rm -rf {} ;

    35.查找并删除指定类型,指定大小的文件

    [root@miyan ~]# find / -type f -name *.mp3 -size +10M -exec rm {} ;

    参考文献:

    http://www.tecmint.com/35-practical-examples-of-linux-find-command/
  • 相关阅读:
    51nod 1179 最大的最大公约数 (数论)
    POJ 3685 二分套二分
    POJ 3045 贪心
    LIC
    HDU 1029 Ignatius and the Princess IV
    HDU 1024 Max Sum Plus Plus
    HDU 2389 Rain on your Parade
    HDU 2819 Swap
    HDU 1281 棋盘游戏
    HDU 1083 Courses
  • 原文地址:https://www.cnblogs.com/XYJK1002/p/5350510.html
Copyright © 2011-2022 走看看