Server Fault is a question and answer site for system and network administrators. 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 create a tarball using tar zcf arhive.tar.gz dir/ and this works ok. Now I wanted to split this into two simple archives, one only for images, the other -- for everything else.

It seems that there's not a trivial and clean way to do this. For tar I can only exclude files, which is unreasonable to exclude every extension except gif, jpg, and png.

To include I have to use find with either -exec or | xargs. This kinda works, but breaks if the filenames have spaces or special characters (apostrophes, quotation marks). So now I have to pipe all the filenames into, say, awk and escape them manually?

What am I missing? Why is this so complicated?

I just wanted tar zcf archive-images.tar.gz dir/ --match-only=*.png

share|improve this question
up vote 6 down vote accepted

use find ... -print0 | xargs -0 tar... these two options exist in order to deal with filenames with spaces.

share|improve this answer
This is not a good idea. You can only pass so many arguments to a process (and when taring up an entire filesystem, isnt too unlikely). The better way is to pipe directly to tar with the --null --files-from arguments. – Patrick Feb 14 '12 at 23:53

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.