用 find 清理空目录
find -type d -empty 可找出不含任何文件和子目录的空目录,配合 -delete 一次性清理。
先运行 `find ~/Downloads -type d -empty -print` 预览,确认后加 `-delete` 删除。
01命令
命令
$ find ~/Downloads -type d -empty -print02作用说明
把文件从同步或解压目录搬走后,常残留大量空文件夹。`find -type d -empty -delete` 只删除真正为空的目录,不会碰还有内容的目录。删除内层空目录后外层也可能变空,find 按深度优先处理,连跑两次即可清理干净。
03风险
!注意: 注意 -delete 会终止其后的其他 find 表达式;删除前先用 -print 预览,尤其在共享或脚本化路径上。
04撤销
撤销
$ null05来源
- find(1) — search for files in a directory hierarchy依据: -type d -empty matches empty directories; -delete removes them
- find(1)依据: documents -empty and -delete ordering cautions
最后验证: 2026-09-18 · 分类: 文件与文件夹