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——必需.规定要分 ...
随机推荐
- Django1.6 +wsgi 部署到Apache2 的步骤。
网上很多教程都是关于1.6之前的版本,很多都不适用,经历告诉我们最靠谱的还是官方文档. 一个Demo例子: 以 python shell开发的方式部署没有问题,但当独立部署到Apache2的过程非常艰 ...
- OSX 10.8+下开启Web共享的方法 /转
OSX 10.8+ Mountain Lion 下开启 Web Sharing(Web 共享)的方法 JUL 28, 2012 #OS X #how-to #apache #web #sha ...
- C++ 类模板一(类模板的定义)
//类模版语法 #include<iostream> using namespace std; /* 类模板和函数模板深入理解 1.编译器并不是把函数模板处理成能处理任何类型的函数 2.编 ...
- php socket编程入门
服务端 <?php /** * File name server.php * 服务器端代码 * * @author guisu.huang * @since 2012-04-11 * */ // ...
- .htaccess伪静态实例分享
首先配置服务器启动重写模块打开 Apache 的配置文件 httpd.conf .将#LoadModule rewrite_module modules/mod_rewrite前面的#去掉.保存后重启 ...
- 日历类Calendar
在早期的JDK版本中,日期(Date)类附有两大功能:(1)允许用年.月.日.时.分.秒来解释日期:(2)允许对表示日期的字符串进行格式化和句法分析.在JDK1.1中提供了类Calendar来完成第一 ...
- tcpdf
将文档整为pdf格式文档 网址:http://www.tcpdf.org/examples.php
- Nucleus PLUS简单介绍
近些年来,随着嵌入式系统飞速的发展,嵌入式实时操作系统广泛地应用在制造工业.过程控制.通讯.仪器仪表.汽车.船舶.航空航天.军事.装备.消费类产 品等方面.今天嵌入式系统带来的工业年产值超过了1万亿美 ...
- hadoop入门学习整理
技术性网站 1.http://dongxicheng.org/ 2.http://www.iteblog.com/ 3.http://www.cnblogs.com/shishanyuan/p/414 ...
- mysql 暴力破解 root账号密码
测试数据库的root账号密码大家都忘记了,好吧,那我们就暴力破解吧 1.找到my.cnf vi /etc/my.cnf在[mysqld]的段中加上一句:skip-grant-tables例如:[mys ...