From Gentoo Wiki
Jump to: navigation, search


GNU tar is an archiver tool that provides the ability to create tar archives, as well as various other kinds of manipulation. The three most used functions are storage, backup and transportation. Five more advanced operations are: --append, --update, --concatenate, --delete and --compare. In addition, tar supports many kinds of compression, among others: gzip, bzip2, lzip, lzma, lzop, xz, and gz.


USE flags

USE flags for app-arch/tar Use this to make tarballs :)

minimal just install `tar` local
static !!do not set this during bootstrap!! Causes binaries to be statically linked instead of dynamically global


After adjusting USE flags:

root #emerge --ask app-arch/tar


root #emerge --ask --depclean app-arch/tar

Environment variables

user $tar --help
displays by default the short tar option summary. This summary is organized by groups. The exact visual representation of the help output is configurable via ARGP_HELP_FMT environment variable. For more information please refer to GNU's tar manual




user $tar --help
Usage: tar [OPTION...] [FILE]...

Most of the tar operations and options can be written in any of three forms: long, short and old style.

The "old style" option forms exist in GNU tar for compatibility with Unix tar.

Three most frequently used options

user $tar --create


user $tar -c
user $tar --list


user $tar -t
user $tar --extract


user $tar -x

Some useful options are:

  • -xz: for tar.gz or .tgz.
  • -xy: for tar.bz2 or .tbz2.
  • -xJ: for tar.xz or .txz.

The fastest way to extract a tarball is tar -xf tarball, because it can recognize any additional extension
Additional options
  • To specify the name of an archive:
user $tar --file=archive-name


user $tar -f archive-name
  • For showing the files being worked on as tar is running:
user $tar --verbose


user $tar -v

For additional information refer to Official documentation


In order to create a compressed tar file, also known as 'tarball', there are many ways, but the best one may be:

user $tar --auto-compress


user $tar -a

This option will select the compression program based on the suffix of the archive file name. For example:

user $tar caf archive.tar.bz2

This command will produce a bz2 tarball, while:

user $ tar -caf archive.tar.lzma

will produce a lzma tarball.

As we mentioned before, the "old" style is maintained for compatibility reasons, and so caf and -caf still work the same way.

Additional information

Because of the wide number of tar's options is not possible to cover all the advanced features of this program on a single wiki entry. Some of the more advanced features include.

  • Add files to existing archives
  • Updating an archive
  • Options used by --extract
  • Performing backups and restoring files
  • Excluding some files
  • Crossing file system boundaries

This information and more is available in the GNU tar manual

See also

  • zip - Provides classic zip compression.
  • p7zip - A command-line port of 7-Zip for POSIX compliant systems.
  • unzip - A decompressor for pkzip-compressed files.

External resources

  • GNU tar: an archiver tool (official).