📖 Linux 文件查找速查(find)

按使用场景分组,点击"复制"按钮一键复制命令

按名称与类型
按文件名查找(区分大小写)
find /path -name "*.log"
按文件名查找(忽略大小写)
find /path -iname "*.log"
只查找文件(排除目录)
find /path -type f -name "*.tmp"
只查找目录
find /path -type d -name "node_modules"
排除指定目录再查找
find /path -path "*/node_modules" -prune -o -name "*.js" -print
按时间
查找 7 天内修改过的文件
find /path -mtime -7
查找超过 30 天未修改的文件
find /path -mtime +30
查找 10 分钟内修改过的文件
find /path -mmin -10
查找比指定文件更新的文件
find /path -newer <ref-file>
按大小
查找大于 100MB 的文件
find /path -type f -size +100M
查找小于 10KB 的文件
find /path -type f -size -10k
查找空文件与空目录
find /path -empty
大文件排行(配合 du 排序)
find /path -type f -exec du -h {} + | sort -rh | head -20
权限与批量处理
按权限查找(如 777 权限文件)
find /path -type f -perm 777
按属主查找文件
find /path -user <username>
查找无主文件(属主已删除)
find /path -nouser
对查找结果批量执行命令
find /path -name "*.log" -exec gzip {} +
批量删除查找结果 ⚠️
find /path -name "*.tmp" -delete