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
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 没有源码,如何修改代码逻辑?
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战