开发者

Collect .txt and .log files using find

开发者 https://www.devze.com 2023-02-03 01:24 出处:网络
I currently have this script to compress log开发者_如何学编程 files: find . -name \'*.log\' -print0 | xargs -0 tar zcf $file

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

精彩评论

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