使用 find 收集 .txt 和 .log 文件
我目前有这个脚本来压缩日志文件:
find . -name '*.log' -print0 | xargs -0 tar zcf $file
当前查找并压缩所有 *.log 文件。我想修改它以包含所有“.txt”文件,但我不知道如何,这应该相当简单,对吧?
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. 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
<代码>查找 . -type f \( -name "*.log" -o -name "*.txt" \) -exec tar zcf "$file" {} +
或者:
find . -type f -regex ".*\.\(txt\|log\)$" -exec tar zcf "$file" {} +
如果您的版本是
find
符合 POSIX 标准,并且可以用+
终止它的-exec
命令(大多数可以)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 offind
is POSIX compliant and can have it's-exec
command terminated with a+
(most can)