繁体   English   中英

使用 find 收集 .txt 和 .log 文件

[英]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.

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