linux find命令

-type 是find命令的一个参数:

-type:查找某一类型文档
b:块设备文档
d:目录
c:字符设备文档
P:管道文档
l:符号链接文档
f:普通文档

把当前目录下面的file(不包括目录),移动到/opt/shell

find  .  -type f  -exec mv {}   /opt/shell   ;

find .  -type f  |  xargs  -I  '{}'  mv  {}  /opt/shell

find /root -size -5557c -size +5555c -exec ls -ld {} ;

//即查找大于5555字节小于5557字节的文件,以上查找的是/root 目录

find /root -size -500K -size +50K -exec ls -ld {} ;

//查找 小于500K,大于50K的文件

find . -name "*" -type f -size 0c | xargs -n 1 rm -f

用这个还可以删除指定大小的文件,只要修改对应的 -size 参数就行,例如:

find . -name "*" -type f -size 1024c | xargs -n 1 rm -f

就是删除1k大小的文件。(但注意不要用 -size 1k,这个得到的是占用空间1k,不是文件大小1k的)。

当某个文件夹下的文件太多,不能使用rm删除

# rm * -rf

-bash: /bin/rm: Argument list too long

网上找了个方法,贴上来给大家分享

find PATH -name *.mp3 -exec rm {} ;

如,要删除 /tmp/123/abc 目录下的

find  /tmp/123/abc ‘*’ -exec rm {} ;

如当前目录为 /tmp/123 ,想删除 /tmp/123/abc 下的

find  ./abc  -name ‘*’ -exec rm {} ;

find . -name "*" -exec rm {} ;

大家可以自己试试,不过要小心处理,别删错重要文件了!!!

-------------------------------------------------------------------------

下面from    http://weiruoyu.blog.51cto.com/951650/832497 

find多少天以前的文件,按时间移动,并分批打包

显示前十个文件

[root@localhost smgpbi]# ls -1 | sort -u | head -10

1.首先查看文件个数,进入所在的文件

# find . -name "*" | wc -l

或者

# ll |grep "^-" |wc -l

2.查看文件个数

查看120天钱的文件个数

# find . -mtime +120 | wc -l

一般如果是小文件,控制在10-20万左右。

解释:-mtime +30 --设置时间为30天前;

-exec mv --查找完毕后执行移动操作;

3.按照时间移动到指定目录里

# find . -mtime +90 -exec mv {} /var/tmp/date_90 ;

4.计算大小

# du -sh date_90

大小一般控制在10-15G最好

5.压缩并打包

#tar -zcvf date_90.tar.gz date_90/

原文地址:https://www.cnblogs.com/rockchip/p/3191867.html