I currently have this script:
find . -name '*.log' -print0 | xargs -0 tar zcf $file
To collect 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?
If you use the
-regex flag instead of
-name you can specify the name as a regular expression:
find . -regex '.*\.\(log\|txt\)' -print0 | xargs -0 tar zcf $file
There are a number of ways to change your find command. Here is one:
find . \( -name '*.log' -o -name '*.txt' \) -print0
-o is an OR operator, thus if the first condition fails, the second condition is checked. If you have GNU find, you can also use the aptly named
-or. Note that the second expression is not evaluated if the first holds.