Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question

2 Answers 2

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
share|improve this answer
    
Thank you - Accepted solution –  Linux Tar Archive query May 21 '11 at 3:29

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.

share|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

Your Answer

 
discard

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.