[英]Collect .txt and .log files using find
我目前有這個腳本來壓縮日志文件:
find . -name '*.log' -print0 | xargs -0 tar zcf $file
當前查找並壓縮所有 *.log 文件。 我想修改它以包含所有“.txt”文件,但我不知道如何,這應該相當簡單吧?
find . -type f \\( -name "*.log" -o -name "*.txt" \\) -exec tar zcf "$file" {} +
或者:
find . -type f -regex ".*\\.\\(txt\\|log\\)$" -exec tar zcf "$file" {} +
如果您的find
版本符合 POSIX 並且可以使用+
終止-exec
命令,則不需要xargs
(大多數可以)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.