简体   繁体   English

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

[英]Collect .txt and .log files using find

I currently have this script to compress log files:我目前有这个脚本来压缩日志文件:

find . -name '*.log' -print0 | xargs -0 tar zcf $file

Currently finds and compress all the *.log files.当前查找并压缩所有 *.log 文件。 I would like to modify it to include also all the ".txt" files but I don't know how, this should be fairly simple right?我想修改它以包含所有“.txt”文件,但我不知道如何,这应该相当简单吧?

find . -type f \\( -name "*.log" -o -name "*.txt" \\) -exec tar zcf "$file" {} +

Alternatively:或者:

find . -type f -regex ".*\\.\\(txt\\|log\\)$" -exec tar zcf "$file" {} +

No need for xargs if your version of find is POSIX compliant and can have it's -exec command terminated with a + (most can)如果您的find版本符合 POSIX 并且可以使用+终止-exec命令,则不需要xargs (大多数可以)

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

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