Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 4 down vote accepted

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
share|improve this answer
This worked, thank you! – OscarRyz Jan 4 '11 at 21:54

There are a number of ways to change your find command. Here is one:

find . \( -name '*.log' -o -name '*.txt' \) -print0

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

share|improve this answer
What does the -o does? – OscarRyz Jan 4 '11 at 21:42
@OscarRyz: See my update. – Steven D Jan 4 '11 at 21:50
I'm only getting the .txt files. :( Thanks anyway +1 – OscarRyz Jan 4 '11 at 21:54
Thanks for the edit Gilles! – Steven D Jan 4 '11 at 22:06
Yeap, that worked, I have +1'ed but to be fair, I'll leave Michael answer as accepted for I have already sent the .tar.gz file via email long ago :) :) – OscarRyz Jan 4 '11 at 22:17

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.