1

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

2

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
1

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.

  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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