I'm trying to create a very large backup of an entire hard disk, using tar. However, there are many files such as CR2 (Canon RAW 2), JPG and a few other files which are already compressed.

I have seen excluding these types of files from the tar archive itself, using the --exclude option, but that is not what I would like to do. Instead, I would like to include these already-compressed files, but skip compression on them, similar to that of rsync's --skip-compress.

Is this possible, and if yes, how can it be done?

  • You could compress the files themselves and then tar the lot.
    – user14755
    May 11, 2016 at 9:08

2 Answers 2


tar itself does not have this feature, you could only filter it so you have two independent tar files, one holding the compressed files, another for the uncompressed files. This can be achieved using tar's exclude option you mentioned, or by building file lists using find.

If you are open to alternatives, there is dar (disk archive) which can decide whether to compress or not for each file individually (-Z, --exclude-compression <mask> option). It can also restore individual files in the archive without uncompressing the whole lot (until the file is found) like tar.

Most people just ignore this problem altogether and compress all files regardless. With a fast compression algorithm it does not make much of a difference. Strong compression takes order of magnitude more CPU time with negligible size reduction (ymmv, depends a lot on the data). If it's an archive that will be downloaded lots of times, strong compression might be worth it, otherwise it may not be.

  • Can selective compression be performed with utilities like xz? May 11, 2016 at 9:36
  • Doesn't matter if it's tar.gz, tar.bz2, tar.xz or other... @roaima's answer explains why, with tar the compression is not content aware. (You can always tar first and compress the entire tar later, same result, tar just does the extra step for you) May 11, 2016 at 10:04

I don't know any way of doing this even with GNU tar.

tar collects the files and then compresses the resulting stream (it's actually the equivalent of tar ... | gzip > somefile.tgz so by the time the compression is applied there is no awareness of individual files.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .