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./unittest/test
/usr/lib64/python2./test
/usr/src/kernels/3.10.-229.14..el7.x86_64/include/config/test
/usr/src/kernels/3.10.-229.14..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  -print
./findtest/test.txt

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

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

9.查找644权限的SGID文件

[root@miyan ~]# find / -perm 

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

[root@miyan ~]# find / -perm 

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  -print -exec chmod  {} \;

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

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

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-.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 

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

[root@miyan ~]# find / -atime 

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

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

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

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

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

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

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

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

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/

最新文章

  1. 【Swift】iOS开发历险记(一)
  2. Nancy+BUI+SQLite自动更新服务端和客户端保护更新程序
  3. android 最详细的动画大全,包括如何在代码和在XML中使用
  4. Swift - 文件目录路径获取及数据储存(Home目录,文档目录,缓存目录)
  5. DDD的思考
  6. WPF QuickStart系列
  7. .net简单页面后台绑定下拉框,按钮,分页 前台aspx页面
  8. Linux内核:sk_buff解析
  9. 3.一步一步学c#(三):对象和类型
  10. AS代码优化和Flex应用程序的性能
  11. PAT 天梯赛 L2-007 家庭房产
  12. Java经典编程题50道之四十一
  13. UNITY VR 视频/图片 开发心得(一)
  14. Saltstack的部署及其详解
  15. Spring boot download file
  16. Centos Git1.7.1升级到Git2.2.1
  17. [Swift]LeetCode401. 二进制手表 | Binary Watch
  18. 20模板方法模式TemplateMethod
  19. Redis学习--key的通用操作、移库操作、订阅与事务、持久化和总结
  20. hive on tez配置

热门文章

  1. Acme Corporation UVA - 11613 拆点法+最大费用最大流(费用取相反数)+费用有正负
  2. &lt;!--#include file= menu.shtml --&gt; 引用出现空白
  3. C语言编写的PHP框架--yaf入门编程
  4. 【vijos】1750 建房子(线段树套线段树+前缀和)
  5. bash脚本IFS=&#39;,&#39; read的意思
  6. python3----生成器generator(yield)
  7. ios --转载-从URL中截取所包含的参数,并且以字典的形式返回和参数字典转URL
  8. 如何正确使用Google搜索
  9. Ubuntu右键添加:open in terminal
  10. 3969 [Mz]平方和【斐波那契平方和】