tar & compression

Arthur Chance freebsd at qeng-ho.org
Fri Jan 18 12:40:26 UTC 2013


On 01/18/13 02:29, Fbsd8 wrote:
> The man page for tar command says there a 4 different compress types you
> can use, xz, bzip, bzip2 and gzip.

bzip and bzip2 are synonyms I believe.

> Which one is the fastest and compresses the most?

The general rule for compression is that fast and high compression are 
opposite ends of the same axis.

> I am using -z option for gzip and it sure is slow.

You can use --options gzip:N or --options xz:N where N is 0-9 to control 
the compression level for gzip or xz compression. 0 is the quickest, but 
least compressing, 9 slowest and most. You'd need to find the trade off 
that works best for you.

> Hoping one of the other zip options are better.
> What do you guys use?

Historically gzip, these days bz2, but that's more habit than any 
scientifically based decision. Compression depends on the data anyway, 
so the only truly correct answer is "whatever works best for you".

> Another question about tar is can I have tar create a compressed bkup
> of 2 files and a directory tree all in single tar command?

tar -cjf tarfile path/to/file1 path/to/file2 path/to/tree/root

or if you don't want to keep path prefixes for the files or tree

tar -cjf tarfile -C file1dir file1 -C file2dir file2 -C dirtree .

Note the '.' at the end of that command.


More information about the freebsd-questions mailing list