[英]How to recursively get all files filtered by multiple extensions within a folder including working folder without using find in Bash script
[英]Bash script find and copy files with multiple extensions including files with 2 or 3 extensions
我有一個bash腳本來查找文件並將其復制到另一個擴展名,
find . -name '*.so' -name '*.lib' -exec cp{} $destination \
上面的腳本只會將所有.so文件復制到$destination
而忽略* .lib。 此外,我在目錄中還有2個或3個擴展名的文件,例如test.so.55 , test1.so.bkk
等。
如何調整上面的代碼,使其可以將所有'*.so'
, '*.lib'
和'*.so.*'
文件復制到$destination
。 此外,我嘗試使用
Try1:
find . -name '*.so' -name '*.lib' -name '*.so.*' -exec cp{} $destination \
乃至
Try2
find . -name '*.so' -exec cp{} $destination \
find . -name '*.so.*' -exec cp{} $destination \
find . -name '*.lib' -exec cp{} $destination \
但是上面的代碼將僅復制Try 1中的*.so and *.lib
文件,而不會復制*.so.*
即*.so.55 , *.so.bkk
中的*.so.55 , *.so.bkk
。
我有成千上萬個文件,如何調整代碼,以便將所有*.so , *.lib and *.so.*
復制到目標位置?
在模式匹配中使用OR
子句:
find . \( -name '*.so' -o -name '*.lib' -o -name '*.so.*' \) -exec cp{} $destination \;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.