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./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/
35个例子学会find的更多相关文章
- Android 使用AsyncTask 下载图片的例子,学会使用AsyncTask
1.添加布局文件:activity_main.xml 1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res ...
- 一个简单的例子学会github repository的webhook
github的webhook是个有用的功能,允许开发人员指定一个服务器的url.当开发者对github仓库施加操作,比如提交代码,创建issue时,github网站会自动向该url指定的服务器推送事件 ...
- Vue组件间通信:一个例子学会Vue组件-Vue.js学习总结)(转载)
详情请点击 http://www.jianshu.com/p/9ad1ba89a04b
- ES6之Promise对象学习——8个例子学会Promise
目录 Promise 立即执行 Promise 三种状态 Promise 不可逆性 链式调用 Promise.then()回调异步性 Promise中的异常 Promise.resolve() res ...
- 黑马程序员_Java基础:集合总结
------- android培训.java培训.期待与您交流! ---------- 一.集合概念 相信大家都知道,java是一门面向对象的编程语言,而对事物的体现都是以对象的形式,所以为了方便对多 ...
- 专业版Unity技巧分享:使用定制资源配置文件
http://unity3d.9tech.cn/news/2014/0116/39639.html 通常,在游戏的开发过程中,最终会建立起一些组件,通过某种形式的配置文件接收一些数据.这些可能是程序级 ...
- Tcpdump使用常用9实例
以下将给出9个使用tcpdump的例子,以说明tcpdump的具体使用方法. 1.针对特定网口抓包(-i选项) 当我们不加任何选项执行tcpdump时,tcpdump将抓取通过所有网口的包:使用-i选 ...
- 放飞App:移动产品经理实战指南
<放飞App:移动产品经理实战指南> 基本信息 原书名:App savvy:rurning ideas into iPhone and iPad Apps customers really ...
- PHP学习系列(1)——字符串处理函数(2)
6.chunk_split() 函数把字符串分割为一连串更小的部分.本函数不改变原始字符串. 语法:chunk_split(string,length,end) 参数: string——必需.规定要分 ...
随机推荐
- 第一百六十一节,封装库--JavaScript,完整封装库文件
封装库--JavaScript,完整封装库文件 /** *feng_zhuang_ku_1.0版本,js封装库,2016/12/29日:林贵秀 **/ /** 前台调用 * 每次调用$()创建库对象, ...
- 嵌入式驱动开发之dsp fpga通信接口---spi串行外围接口、emif sram接口
-----------------------------------------author:pkf ------------------------------------------------ ...
- js常用API汇总(转)
typeof(); 检测数据类型 String(); 转换成字符串 parseInt(); 解析出一个string或number的整数部分 parseFloat(); 解析出一个string的浮点数部 ...
- 让TextView的drawableLeft与文本一起居中显示
TextView的drawableLeft.drawableRight和drawableTop是一个常用.好用的属性,可以在文本的上下左右放置一个图片,而不使用更加复杂布局就能达到,我也常常喜欢用R ...
- servlet ; basepath ; sendredirected ;
Eclipse 新建 jsp页面里自动生成以下代码: <%String path = request.getContextPath();String basePath = request.get ...
- 理解PHP中会话控制
如果以前没有接触过建站或网络编程,只是从头开始学PHP,以及用PHP来建立动态站点,那么会话(SESSION)对于初学者就有点难理解.那么到底什么是会话呢?理解一个概念需要从它产生的背景或问题出发,所 ...
- 【JDF】学习和理解
一.资源地址 官方GitBub地址: putaoshu/jdf: Jingdong front-end integrated solution https://github.com/putaoshu/ ...
- cocopods
一.什么是CocoaPods 1.为什么需要CocoaPods 在进行iOS开发的时候,总免不了使用第三方的开源库,比如SBJson.AFNetworking.Reachability等等.使用这些库 ...
- VS2008里的代码如何格式化
选中要格式化的代码, 先按Ctrl+K 再按Ctrl+F 从菜单中也可以 "编辑"->"高级"->"设置文档的格式Ctrl+K Ctrl+ ...
- python split(),os.path.split()和os.path.splitext()函数用法
https://blog.csdn.net/T1243_3/article/details/80170006 # -*- coding:utf-8 -*- """ @ ...