http://www.gnu.org/software/tar/ ... Formats.html#SEC132
8.1.1 Creating and Reading Compressed Archives
GNU tar is able to create and read compressed archives. It supports a wide variety of compression programs, namely: gzip, bzip2, lzip, lzma, lzop, xz and traditional compress. The latter is supported mostly for backward compatibility, and we recommend against using it, because it is by far less effective than the other compression programs(18).
Creating a compressed archive is simple: you just specify a compression option along with the usual archive creation commands. The compression option is ‘-z’ (‘--gzip’) to create a gzip compressed archive, ‘-j’ (‘--bzip2’) to create a bzip2 compressed archive, ‘--lzip’ to create an lzip compressed archive, ‘-J’ (‘--xz’) to create an XZ archive, ‘--lzma’ to create an LZMA compressed archive, ‘--lzop’ to create an LSOP archive, and ‘-Z’ (‘--compress’) to use compress program. For example:
$ tar cfz archive.tar.gz .
You can also let GNU tar select the compression program based on the suffix of the archive file name. This is done using ‘--auto-compress’ (‘-a’) command line option. For example, the following invocation will use bzip2 for compression:
$ tar cfa archive.tar.bz2 .
whereas the following one will use lzma:
$ tar cfa archive.tar.lzma .
For a complete list of file name suffixes recognized by GNU tar, see auto-compress.
Reading compressed archive is even simpler: you don't need to specify any additional options as GNU tar recognizes its format automatically. Thus, the following commands will list and extract the archive created in previous example:
# List the compressed archive
$ tar tf archive.tar.gz
# Extract the compressed archive
$ tar xf archive.tar.gz
The format recognition algorithm is based on signatures, a special byte sequences in the beginning of file, that are specific for certain compression formats. If this approach fails, tar falls back to using archive name suffix to determine its format (see auto-compress, for a list of recognized suffixes).
Some compression programs are able to handle different compression formats. GNU tar uses this, if the principal decompressor for the given format is not available. For example, if compress is not installed, tar will try to use gzip. As of version 1.26 the following alternatives are tried(19): |