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

发布于 2024-10-10 05:24:55 字数 169 浏览 0 评论 0原文

我目前有这个脚本来压缩日志文件:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

神经暖 2024-10-17 05:24:55

<代码>查找 . -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 of find is POSIX compliant and can have it's -exec command terminated with a + (most can)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文