tar: gzip

1 
1 8.1.1 Creating and Reading Compressed Archives
1 ----------------------------------------------
1 
1 GNU 'tar' is able to create and read compressed archives.  It supports a
1 wide variety of compression programs, namely: 'gzip', 'bzip2', 'lzip',
1 'lzma', 'lzop', 'xz' and traditional 'compress'.  The latter is
1 supported mostly for backward compatibility, and we recommend against
1 using it, because it is by far less effective than the other compression
1 programs(1).
1 
1    Creating a compressed archive is simple: you just specify a
1 "compression option" along with the usual archive creation commands.
1 The compression option is '-z' ('--gzip') to create a 'gzip' compressed
1 archive, '-j' ('--bzip2') to create a 'bzip2' compressed archive,
1 '--lzip' to create an lzip compressed archive, '-J' ('--xz') to create
1 an XZ archive, '--lzma' to create an LZMA compressed archive, '--lzop'
1 to create an LZOP archive, and '-Z' ('--compress') to use 'compress'
1 program.  For example:
1 
1      $ tar czf archive.tar.gz .
1 
1    You can also let GNU 'tar' select the compression program based on
1 the suffix of the archive file name.  This is done using
1 '--auto-compress' ('-a') command line option.  For example, the
1 following invocation will use 'bzip2' for compression:
1 
1      $ tar caf archive.tar.bz2 .
1 
1 whereas the following one will use 'lzma':
1 
1      $ tar caf archive.tar.lzma .
1 
1    For a complete list of file name suffixes recognized by GNU 'tar',
1 see ⇒auto-compress.
1 
1    Reading compressed archive is even simpler: you don't need to specify
1 any additional options as GNU 'tar' recognizes its format automatically.
1 Thus, the following commands will list and extract the archive created
1 in previous example:
1 
1      # List the compressed archive
1      $ tar tf archive.tar.gz
1      # Extract the compressed archive
1      $ tar xf archive.tar.gz
1 
1    The format recognition algorithm is based on "signatures", a special
1 byte sequences in the beginning of file, that are specific for certain
1 compression formats.  If this approach fails, 'tar' falls back to using
1 archive name suffix to determine its format (⇒auto-compress, for
1 a list of recognized suffixes).
1 
1    Some compression programs are able to handle different compression
1 formats.  GNU 'tar' uses this, if the principal decompressor for the
1 given format is not available.  For example, if 'compress' is not
1 installed, 'tar' will try to use 'gzip'.  As of version 1.30 the
1 following alternatives are tried(2):
1 
1 Format                 Main decompressor      Alternatives
1 ---------------------------------------------------------------------
1 compress               compress               gzip
1 lzma                   lzma                   xz
1 bzip2                  bzip2                  lbzip2
1 
1    The only case when you have to specify a decompression option while
1 reading the archive is when reading from a pipe or from a tape drive
1 that does not support random access.  However, in this case GNU 'tar'
1 will indicate which option you should use.  For example:
1 
1      $ cat archive.tar.gz | tar tf -
1      tar: Archive is compressed.  Use -z option
1      tar: Error is not recoverable: exiting now
1 
1    If you see such diagnostics, just add the suggested option to the
1 invocation of GNU 'tar':
1 
1      $ cat archive.tar.gz | tar tzf -
1 
1    Notice also, that there are several restrictions on operations on
1 compressed archives.  First of all, compressed archives cannot be
1 modified, i.e., you cannot update ('--update', alias '-u') them or
1 delete ('--delete') members from them or add ('--append', alias '-r')
1 members to them.  Likewise, you cannot append another 'tar' archive to a
1 compressed archive using '--concatenate' ('-A').  Secondly, multi-volume
1 archives cannot be compressed.
1 
1    The following options allow to select a particular compressor
1 program:
1 
1 '-z'
1 '--gzip'
1 '--ungzip'
1      Filter the archive through 'gzip'.
1 
1 '-J'
1 '--xz'
1      Filter the archive through 'xz'.
1 
1 '-j'
1 '--bzip2'
1      Filter the archive through 'bzip2'.
1 
1 '--lzip'
1      Filter the archive through 'lzip'.
1 
1 '--lzma'
1      Filter the archive through 'lzma'.
1 
1 '--lzop'
1      Filter the archive through 'lzop'.
1 
1 '-Z'
1 '--compress'
1 '--uncompress'
1      Filter the archive through 'compress'.
1 
1    When any of these options is given, GNU 'tar' searches the compressor
1 binary in the current path and invokes it.  The name of the compressor
1 program is specified at compilation time using a corresponding
1 '--with-COMPNAME' option to 'configure', e.g.  '--with-bzip2' to select
1 a specific 'bzip2' binary.  ⇒lbzip2, for a detailed discussion.
1 
1    The output produced by 'tar --help' shows the actual compressor names
1 along with each of these options.
1 
1    You can use any of these options on physical devices (tape drives,
1 etc.) and remote files as well as on normal files; data to or from such
1 devices or remote files is reblocked by another copy of the 'tar'
1 program to enforce the specified (or default) record size.  The default
1 compression parameters are used.  You can override them by using the
1 '-I' option (see below), e.g.:
1 
1      $ tar -cf archive.tar.gz -I 'gzip -9 -n' subdir
1 
1 A more traditional way to do this is to use a pipe:
1 
1      $ tar cf - subdir | gzip -9 -n > archive.tar.gz
1 
1    Compressed archives are easily corrupted, because compressed files
1 have little redundancy.  The adaptive nature of the compression scheme
1 means that the compression tables are implicitly spread all over the
1 archive.  If you lose a few blocks, the dynamic construction of the
1 compression tables becomes unsynchronized, and there is little chance
1 that you could recover later in the archive.
1 
1    Other compression options provide better control over creating
1 compressed archives.  These are:
1 
1 '--auto-compress'
1 '-a'
1      Select a compression program to use by the archive file name
1      suffix.  The following suffixes are recognized:
1 
1      Suffix                 Compression program
1      -------------------------------------------------------------------
1      '.gz'                  'gzip'
1      '.tgz'                 'gzip'
1      '.taz'                 'gzip'
1      '.Z'                   'compress'
1      '.taZ'                 'compress'
1      '.bz2'                 'bzip2'
1      '.tz2'                 'bzip2'
1      '.tbz2'                'bzip2'
1      '.tbz'                 'bzip2'
1      '.lz'                  'lzip'
1      '.lzma'                'lzma'
1      '.tlz'                 'lzma'
1      '.lzo'                 'lzop'
1      '.xz'                  'xz'
1 
1 '--use-compress-program=COMMAND'
1 '-I=COMMAND'
1      Use external compression program COMMAND.  Use this option if you
1      want to specify options for the compression program, or if you are
1      not happy with the compression program associated with the suffix
1      at compile time, or if you have a compression program that GNU
1      'tar' does not support.  The COMMAND argument is a valid command
1      invocation, as you would type it at the command line prompt, with
1      any additional options as needed.  Enclose it in quotes if it
1      contains white space (⇒Running External Commands external.).
1 
1      The COMMAND should follow two conventions:
1 
1      First, when invoked without additional options, it should read data
1      from standard input, compress it and output it on standard output.
1 
1      Secondly, if invoked with the additional '-d' option, it should do
1      exactly the opposite, i.e., read the compressed data from the
1      standard input and produce uncompressed data on the standard
1      output.
1 
1      The latter requirement means that you must not use the '-d' option
1      as a part of the COMMAND itself.
1 
1    The '--use-compress-program' option, in particular, lets you
1 implement your own filters, not necessarily dealing with
1 compression/decompression.  For example, suppose you wish to implement
11 PGP encryption on top of compression, using 'gpg' (⇒gpg
 (gpg)Top.).  The following script does that:
1 
1      #! /bin/sh
1      case $1 in
1      -d) gpg --decrypt - | gzip -d -c;;
1      '') gzip -c | gpg -s;;
1      *)  echo "Unknown option $1">&2; exit 1;;
1      esac
1 
1    Suppose you name it 'gpgz' and save it somewhere in your 'PATH'.
1 Then the following command will create a compressed archive signed with
1 your private key:
1 
1      $ tar -cf foo.tar.gpgz -Igpgz .
1 
1 Likewise, the command below will list its contents:
1 
1      $ tar -tf foo.tar.gpgz -Igpgz .
1 

Menu