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

猜你喜欢

转载自www.cnblogs.com/qianjingchen/p/11297241.html