首页 > 系统服务 > 详细

Linux 之 find 命令使用详解(第六章)

时间:2018-05-06 10:24:07      阅读:184      评论:0      收藏:0      [点我收藏+]
find 命令场境
1.查找/root/kang目录下的所有文件
find /root/kang -type f
[root@localhost kang]# find /root/kang/ -type f
/root/kang/kang.txt
/root/kang/test.txt

2.查找/root/kang目录下所有文件夹
[root@localhost kang]# find /root/kang/ -type d
/root/kang/
/root/kang/nginx

3.查找/root/kang目录下,文件名为‘kang.txt‘的文件
[root@localhost kang]# find /root/kang/ -type f -name "kang.txt"
/root/kang/kang.txt

4.查找/root/kang目录下为文件名为test.txt的文件,直接删除
[root@localhost kang]# ll
total 8
kang.txt nginx test.txt
[root@localhost kang]# find /root/kang/ -type f -name "test.txt" -exec rm {} \;
[root@localhost kang]# ls
kang.txt  nginx

备注:另外一种删除方法:
find /root/kang/ -type f |xargs rm -rf
xargs是一个命令,等于find找到的文件打成一行,将赋给rm -rf 后面执行
即:
[root@localhost kang]# find /root/kang/ -type f|xargs
/root/kang/kang.txt /root/kang/test.txt

5.查找大于7天的文件,并删除
find /backup/exp_backup/ -name "*.dmp" -mtime +7 -exec rm -rf {} \;
或者:
find /backup/exp_backup/ -name "*.dmp" -mtime +7 |xargs rm -rf

6.mtime 解释
+7:7天以前的数据
7:第7天的数据
-7:最近7天的数据

Linux 之 find 命令使用详解(第六章)

原文:http://blog.51cto.com/12965094/2113075

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!