tar

From Gentoo Wiki
Jump to: navigation, search

Resources

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.

Installation

USE flags

Cannot load package information. Is the atom app-arch/tar correct?

Emerge

After adjusting USE flags:

root #emerge --ask app-arch/tar

Removal

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

Usage

Invocation

help

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.

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

Three most frequently used options

Creation
user $tar --create

or

user $tar -c
Listing
user $tar --list

or

user $tar -t
Extraction
user $tar --extract

or

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.


Note
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

or

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

or

user $tar -v

For additional information refer to Official documentation

Compression

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

or

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.

Note
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 programm 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).