如何使用find收集所有“txt”和“log”文件?

Osc*_*Ryz 5 scripts find

我目前有这个脚本:

find . -iname '*.log' -print0 | xargs -0 tar zcf $file
Run Code Online (Sandbox Code Playgroud)

从给定目录收集所有“*.log”文件。我想修改它以包含所有“.txt”文件,但我不知道如何,这应该相当简单吧?

Rap*_*sek 2

你走在正确的道路上。尝试这个:

find . \( -iname "*.log" -or -iname "*.txt" \) -print0 | xargs -0 tar zcf $file

  • 这将一直有效到某一点。如果 find 找到的文件超过最大参数长度,xargs 会将尽可能多的文件传递给 tar,然后使用剩余的文件再次运行它。这意味着,第二个 tar 将覆盖第一个 tar 制作的存档。 (2认同)