linux - find 查找文件

1. -name 在当前目录以及子目录中根据文件名进行查找

find -name "apt.md"

2. -iname 忽略大小写进行查找

find -iname "apt.md"

3. -mindepth, -maxdepth 设置从根目录下查找的目录层级

find / -mindepth 3 -maxdepth 5 -name passwd

4. -exec 对查找到的文件执行命令

find -name '*.md' -exec md5sum {} \;

5. -not 显示不匹配的查找结果

find -not -iname "apt.md"

6. -inum 通过文件的inode值进行查找并执行命令

ls -il  // 查看文件inode 值
find -inum 1187273 -exec rm {} \;

7. -perm 根据分组具有读权限进行查找

find . -perm -g=r -type f -exec ls -l {} \;

8. -empty 在用户目录查找空文件

find ~ -empty

9. 在当前目录查找最大的5个文件和最小的5个文件

# 查找最大5个文件
find . -type f -exec ls -s {} \; | sort -n -r | head -5
# 查找最小5个文件
find . -type f -exec ls -s {} \; | sort -n  | head -5
# 查找最小5个文件并且非空文件
find . -not -empty -type f -exec ls -s {} \; | sort -n  | head -5

10. 基于文件类型进行查找

# 查找目录
find . -type d
# 查找普通文件
find . -type f
# 查找所有隐藏的文件
find . -type f -name ".*"

11. 基于文件的修改时间进行查找

find -newer ordinary_file

12. 基于文件大小进行查找

find ~ -size +100M # 大于100M
find ~ -size -100M # 小于100M
find ~ -size 100M # 等于100M

posted @   箫笛  阅读(511)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 没有源码,如何修改代码逻辑?
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
点击右上角即可分享
微信分享提示