开发者

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. 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?


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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜