简体   繁体   中英

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM