簡體   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