From Gentoo Wiki
Jump to:navigation Jump to: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 :)

acl Add support for Access Control Lists
minimal just install `tar`
nls Add Native Language Support (using gettextGNU locale utilities)
selinux !!internal use only!! Security Enhanced Linux support, this must be set by the selinux profile or breakage will occur
verify-sig Verify upstream signatures on distfiles
xattr Add support for extended attributes (filesystem-stored metadata)


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


There are many ways to create a compressed tar file, also known as a 'tarball'. 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 mentioned previously, the "old" style is maintained for compatibility reasons; therefore caf and -caf still work the same way.

Additional information

Because of the wide variety of tar's options, it is not possible to cover all the advanced features of this program with a single wiki entry. Some of the more advanced features include:

  • Adding files to existing archives;
  • Updating an archive;
  • Specifying options with --extract;
  • Backing up and restoring files;
  • Excluding some files; and
  • Crossing file system boundaries.

This information and more is available in the GNU tar manual

See also

  • Backup — prevent loss of data by ensuring it can be recovered.
  • Zip — provides classic zip compression.
  • P7zip — a command-line port of 7-Zip for POSIX compliant systems such as Unix, OS X, BeOS, and Amiga.
  • Unzip — provides decompression for classic zip formats.

External resources