繁体   English   中英

重击:“查找”中的编号文件

[英]Bash: numbered files in Find

我正在编写一个bash脚本,该脚本查找和删除Blender在编辑和保存.blend文件时创建的.blend1和.blend2文件。 它包含成对的行,如下所示:

find Documents -name "*.blend1" -exec rm -rf {} \;
find Documents -name "*.blend2" -exec rm -rf {} \;

这很好用,尽管我很好奇是否可以以某种方式组合这两个find命令,以便它只是查找和删除.blend1和.blend2文件的一个命令。

不是很重要,如果脚本更紧凑,我会更喜欢它。

find Documents -name '*.blend[12]' -delete

-delete是GNU查找扩展名。)

其他方法:

find Documents '(' -name '*.blend1' -o -name '*.blend2' ')' -delete
find Documents -name '*.blend*' -delete

这是另一种方式

find Documents -name '*.blend[12]' -exec rm -rf {} \;

是的,您可以使用正则表达式将一种以上的模式匹配为一种:

find Documents -regextype posix-egrep -regex '.*\.(blend1|blend2)$' -exec rm -rf {} \;

或使用较新的find版本:

find Documents -regextype posix-egrep -regex '.*\.(blend1|blend2)$' -delete

没有正则表达式,您可以执行以下操作:

find Documents \( -name "*.blend1" -o -name "*.blend2" \) -delete

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM