Files
tldr/pages.zh/common/find.md

36 lines
1.1 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 查找
> 在目录树下递归查找文件或目录。
> 更多信息:<https://manned.org/find>。
- 按扩展名查找文件:
`find {{root_path}} -name '{{*.ext}}'`
- 查找匹配多个路径/名称模式的文件:
`find {{root_path}} -path '{{**/path/**/*.ext}}' -or -name '{{*pattern*}}'`
- 以不区分大小写的模式查找匹配给定名称的目录:
`find {{root_path}} -type d -iname '{{*lib*}}'`
- 查找匹配给定模式的文件,排除特定路径:
`find {{root_path}} -name '{{*.py}}' -not -path '{{*/site-packages/*}}'`
- 查找匹配给定大小范围的文件将递归深度限制为“1”
`find {{root_path}} -maxdepth 1 -size {{+500k}} -size {{-10M}}`
- 对每个文件运行一个命令(在命令中使用 `{}` 访问文件名):
`find {{root_path}} -name '{{*.ext}}' -exec {{wc -l}} {} \;`
- 查找今天修改的所有文件并将结果作为参数传递给单个命令:
`find {{root_path}} -daystart -mtime {{-1}} -exec {{tar -cvf archive.tar}} {} \+`
- 查找空文件0字节或目录并详细删除它们
`find {{root_path}} -type {{f|d}} -empty -delete -print`