find常规使用方法

1. find查找包含字符的文件

  如:我想查找包含 server_name www.kalaok.com的配置文件

find . -type f |xargs grep "server_name www.kalaok.com"

2. find查找log文件并清空

  目的:有些日志文件不重要,但是又占用空间,就可以使用此方法:

# 以下两种方法都可以
find /datadisk1 -type f -name "*.log"  -size +500M | xargs -I files sh -c 'echo "" > $1' -- files 
find /datadisk1 -type f -name "*.log"  -size +500M -exec cp /dev/null {} \;

3. 查找空文件或空目录

  查找当前目录下文件大小为0的文件

[root@linux-noed1 ~]# find ./ -type f -size 0
./5230.txt
./.ssh/authorized_keys

  查找空目录,加上-empty

[root@globalloges ~]# find ./ -type d -empty
./.pki/nssdb

  其他用法请自行参考:https://www.cnblogs.com/bianchengzhuji/p/10133821.html

转载于:https://www.cnblogs.com/qianjingchen/p/11297241.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值