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 Answers2

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
Ignacio Vazquez-Abrams
  • 45,939
  • 6
  • 79
  • 84
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.

dmourati
  • 25,540
  • 2
  • 42
  • 72