文件查找find命令

 

 

#!/bin/bash
find /etc -name '*.conf'
find /etc -iname "aa"   #不区分大小写
find . -user hdfs
find . -group yarn

find /etc -type f       #文件
find /etc -type d       #路径

find /etc -size +1M     #文件大小大于1M
find /etc -size -100k   #文件大小小于100k

find /etc -mtime -5 -name '*.conf'      #5天内修改的文件
find /etc -mtime +10 -user root         #10天前属主用户是root修改的文件

find /etc -mmin -10                     #10min内修改的文件
find /etc -mmin -10 -type d             #10min前修改过的路径

find /etc -mindepth 3   #/etc的三级子目录开始搜索
find /etc -maxdepth 3   #最多搜索n级子目录

find . -path ./test -prune -o -path ./test2 -prune -o -type f -a -size +500k     #查找当前路径下所有普通文件,并且文件大小大于500k,但排除 test1、test2路径下的文件

find /root/test -type f -exec rm -f {} \;
find /root/test -type f -exec cp {}  ./ \;

例1:搜索etc下的文件(非目录),文件名以conf结尾,且大于10k,然后将其删除
          find ./etc -type f -name '*.comf' -size +10k -exec rm -f {} \;
例2:将/var/log/目录下以log结尾的文件,且更改时间在7天以上的删除
          find /var/log -type f -name '*.log' -mtime +7 -exec rm -f {} \;
例3:搜索条件和例子1一样,只是不删除,而是将其复制到/root/conf目录下
          find ./etc -type f -name '*.conf' -size +10k -exec cp {} /root/conf \;

 

注:使用locate查找文件,立即生效需执行updatedb命令。

 

 

  • 6
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值