What is the best way to archive select file extensions in an unknown tree. I cannot use exclude options in tar/gzip/rsync as it would be impossible to exclude all possible extension variations.

Example to backup all .foo and .bar files in a recursive tree but not other unknown file types.

I presume this will need to be a combination of ls/find, grep and tar/gzip.

Thank you

link|improve this question
feedback

2 Answers

up vote 2 down vote accepted

Very similar to dmourati's answer, but without xargs.

find /path/to/tree \( -name "*.foo" -o -name "*.bar" \) -print0 | tar -T /dev/stdin --null -cvzf foobar.tar.gz
link|improve this answer
Thank you - Accepted solution – Linux Tar Archive query May 21 '11 at 3:29
feedback

Try something like this:

find /path/to/tree \( -name "*.foo" -o -name "*.bar" \) -print0 | xargs -r0 tar cvzf foobar.tar.gz

You generate the list of files via the find command and then pipe that to xargs and on to tar.

link|improve this answer
This could cause issues if there are too many files for xargs to put in a single command. – Ignacio Vazquez-Abrams May 21 '11 at 3:16
There are a lot of them and the tree does get quite deep in places – Linux Tar Archive query May 21 '11 at 3:18
Maybe just me but it seams to be ignoring the first file extension and just tar'ing the second. – Linux Tar Archive query May 21 '11 at 3:23
Editted to fix the grouping – dmourati May 21 '11 at 3:23
Thats fixed it - Thank you. – Linux Tar Archive query May 21 '11 at 3:27
feedback

Your Answer

 
or
required, but never shown

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