1.按文件名字
ind /tmp -name “1.txt” 已知路径
find / -name “1.txt” 未知路径
touch file1 touch File1
find /tmp -iname “file1”
>>> /tmp/file1
>>./tmp/File1 -iname 忽略大小写
find /tmp -name “*.txt” 查找以.txt结尾的一类文件
2.按文件大小
find /tmp -size 5M 在/tmp下查找等于5M的文件
。。。。。。-5M (小于5M) 。。。。+5M (大于5M)
3.按文件深度
find /etc -maxdepth 3 -a -name “ifcfg-ens33”
-maxdepth 3 文件深度 -a 并且 同时满足
4.按文件时间
find /tmp -mtime +5 修改时间超过5天
永久修改当前系统时间 月日时分
date 月日时分
5.按文件类型
find /tmp/ -type f 查找/tmp下所有的文件
find /tmp/ -type d 查找/tmp下所有的目录
find /tmp-empty
找出/tmp下所有的空文件或目录
6.统计文件个数
find /tmp/ -type f | wc -l
统计/tmp下的文件个数
find /tmp/ -name “*.txt” | wc -l
统计/tmp下的以.txt结尾的文件
find /tmp/ -type d | wc -l 统计/tmp下的目录 (包括隐藏)
7.按权限查找(不限文件目录)
find . -perm 644
查找在当前目录下权限为644的东西
find . -perm -644 (-644包括644) (. 表示当前目录)
linux中创建文件默认的权限为644
创建目录默认的权限为755
8.find /tmp -name “file1” -o -name “file5” -o 或者
,和 在/tmp下找file1或者file5
9.find /tmp/ ! -name “file1” (! 非,取反)
找到/tmp下不要file1的文件
10.find /tmp/ ! -name “file*” 不要file*
-exec 固定的 参数传递 找到一条就执行一次后面的命令 启动进程多
{} 占位符
{} ; 固定格式 ;结尾
find /tmp/ -name "2.txt" -exec rm -rf {} \;
在/tmp下找出2.txt并删除
find /tmp/ -name ".txt" -exec cp -rvf {} / ; (/ 根 ,路径;-v 显示过程)
在/tmp下找出.txt 复制到/下并显示出过程
find /tmp/ -name ".txt" -exec mv {} / ; (/ 根路径)
在/tmp下找出.txt 移动到/下
find . -name “*.txt” | xargs rm -rf
找出*.txt 并删除
xargs 传递参数 全部找出后执行后面的命令
不会出现重命名覆盖