Table of Contents
creates and manipulates streaming archive files. This implementation can
extract from tar, pax, cpio, zip, jar, ar, and ISO 9660 cdrom images and
can create tar, pax, cpio, ar, and shar archives. The first synopsis form
shows a option word. This usage is provided for compatibility with historical
implementations. See COMPATIBILITY below for details. The other synopsis
forms show the preferred usage. The first option to is a mode indicator
from the following list: Create a new archive containing the specified
items. Like but new entries are appended to the archive. Note that this
only works on uncompressed archives stored in regular files. The option
is required. List archive contents to stdout. Like but new entries are
added only if they have a modification date newer than the corresponding
entry in the archive. Note that this only works on uncompressed archives
stored in regular files. The option is required. Extract to disk from the
archive. If a file with the same name appears more than once in the archive,
each copy will be extracted, with later copies overwriting (replacing)
earlier copies. In or mode, each specified file or directory is added
to the archive in the order specified on the command line. By default, the
contents of each directory are also archived. In extract or list mode,
the entire command line is read and parsed before the archive is opened.
The pathnames or patterns on the command line indicate which items in the
archive should be processed. Patterns are shell-style globbing patterns as
documented in
Unless specifically stated otherwise, options are
applicable in all operating modes. (c and r mode only) The specified archive
is opened and the entries in it will be appended to the current archive.
As a simple example, writes a new archive to standard output containing
a file and all of the entries from In contrast, creates a new archive
with only two entries. Similarly, reads an archive from standard input
(whose format will be determined automatically) and converts it into a
gzip-compressed pax-format archive on stdout. In this way, can be used to
convert archives from one format to another. Specify the block size, in
512-byte records, for tape drive I/O. As a rule, this argument is only needed
when reading from or writing to tape drives, and usually not even then
as the default block size of 20 records (10240 bytes) is very common. In
c and r mode, this changes the directory before adding the following files.
In x mode, change directories after opening the archive but before extracting
entries from the archive. (c and r modes only) Issue a warning message
unless all links to each file are archived. Do not process files or directories
that match the specified pattern. Note that exclusions take precedence over
patterns or filenames specified on the command line. (c mode only) Use
the specified format for the created archive. Supported formats include
and Other formats may also be supported; see for more information
about currently-supported formats. Read the archive from or write the archive
to the specified file. The filename can be for standard input or standard
output. If not specified, the default tape device will be used. (On the
default tape device is (x and t mode only) Extract or list only the first
archive entry that matches each pattern or filename operand. Exit as soon
as each specified pattern or filename has been matched. By default, the
archive is always read to the very end, since there can be multiple entries
with the same name and, by convention, later entries overwrite earlier
entries. This option is provided as a performance optimization. (c and r
mode only) Symbolic links named on the command line will be followed; the
target of the link will be archived, not the link itself. (c and r mode
only) Synonym for Synonym for Process only files or directories that
match the specified pattern. Note that exclusions specified with take precedence
over inclusions. If no inclusions are explicitly specified, all entries
are processed by default. The option is especially useful when filtering
archives. For example, the command creates a new archive containing only
the entries from containing the string (c mode only) Compress the resulting
archive with In extract or list modes, this option is ignored. Note that,
unlike other implementations, this implementation recognizes bzip2 compression
automatically when reading archives. (x mode only) Do not overwrite existing
files. In particular, if a file appears more than once in an archive, later
copies will not overwrite earlier copies. (c and r mode only) All symbolic
links will be followed. Normally, symbolic links are archived as such. With
this option, the target of the link will be archived instead. This is a
synonym for the option. (x mode only) Do not extract modification time.
By default, the modification time is set to the time stored in the archive.
(c, r, u modes only) Do not recursively archive the contents of directories.
(c, r, u modes only) Only include files and directories newer than the
specified date. This compares ctime entries. (c, r, u modes only) Like
except it compares mtime entries instead of ctime entries. (c, r, u modes
only) Only include files and directories newer than the specified file.
This compares ctime entries. (c, r, u modes only) Like except it compares
mtime entries instead of ctime entries. (c and r modes only) Honor the
nodump file flag by skipping this file. (use with or Filenames or patterns
are separated by null characters, not by newlines. This is often used to
read filenames output by the option to (x, t modes only) In extract
(-x) mode, files will be written to standard out rather than being extracted
to disk. In list (-t) mode, the file listing will be written to stderr rather
than the usual stdout. (x mode only) Use the user and group of the user
running the program rather than those specified in the archive. Note that
this has no significance unless is specified, and the program is being
run by the root user. In this case, the file modes and flags from the archive
will be restored, but ACLs or owner information in the archive will be
discarded. (c, r, and u modes) Do not cross mount points. Preserve pathnames.
By default, absolute pathnames (those that begin with a / character) have
the leading slash removed both when creating archives and extracting from
them. Also, will refuse to extract archive entries whose pathnames contain
or whose target directory would be altered by a symlink. This option suppresses
these behaviors. (x mode only) Preserve file permissions. Attempt to restore
the full permissions, including owner, file modes, file flags and ACLs,
if available, for each item extracted from the archive. By default, newly-created
files are owned by the user running the file mode is restored for newly-created
regular files, and all other types of entries receive default permissions.
If is being run by root, the default is to restore the owner unless the
option is also specified. (x and t mode only) Remove the specified number
of leading path elements. Pathnames with fewer elements will be silently
skipped. Note that the pathname is edited after checking inclusion/exclusion
patterns but before security checks. In x or t mode, will read the list
of names to be extracted from In c mode, will read names to be archived
from The special name on a line by itself will cause the current directory
to be changed to the directory specified on the following line. Names are
terminated by newlines unless is specified. Note that also disables the
special handling of lines containing (x mode only) Unlink files before
creating them. Without this option, overwrites existing files, which preserves
existing hardlinks. With this option, existing hardlinks will be broken,
as will any symlink that would affect the location of an extracted file.
Pipe the input (in x or t mode) or the output (in c mode) through instead
of using the builtin compression support. Produce verbose output. In create
and extract modes, will list each file name as it is read from or written
to the archive. In list mode, will produce output similar to that of Additional
options will provide additional detail. Long options (preceded by are
only supported directly on systems that have the function. The option
can be used to access long options on systems that do not support this
function. Ask for confirmation for every action. Read a list of exclusion
patterns from the specified file. See for more information about the handling
of exclusions. (c mode only) Compress the resulting archive with In extract
or list modes, this option is ignored. Note that, unlike other implementations,
this implementation recognizes bzip2 compression automatically when reading
archives. (c mode only) Compress the resulting archive with In extract
or list modes, this option is ignored. Note that, unlike other implementations,
this implementation recognizes gzip compression automatically when reading
archives.
The following environment variables affect the execution
of The locale to use. See for more information. The default tape device.
The option overrides this. The timezone to use when displaying dates. See
for more information.
The default tape device, if not overridden
by the environment variable or the option.
The following
creates a new archive called that contains two files and To view a
detailed table of contents for this archive: To extract all entries from
the archive on the default tape drive: To examine the contents of an
ISO 9660 cdrom image: To move file hierarchies, invoke as or more traditionally
In create mode, the list of files and directories to be archived can
also include directory change instructions of the form and archive inclusions
of the form For example, the command line will create a new archive
will read the file from the current directory and add it to the output
archive. It will then read each entry from and add those entries to the
output archive. Finally, it will switch to the directory and add to the
output archive. The and switches accept a variety of common date and
time specifications, including and
The bundled-arguments
format is supported for compatibility with historic implementations. It
consists of an initial word (with no leading - character) in which each
character indicates an option. Arguments follow as separate words. The order
of the arguments must match the order of the corresponding characters in
the bundled command word. For example, specifies three flags and The
and flags both require arguments, so there must be two additional items
on the command line. The is the argument to the flag, and is the argument
to the flag. The mode options c, r, t, u, and x and the options b, f,
l, m, o, v, and w comply with SUSv2. For maximum portability, scripts that
invoke should use the bundled-argument format above, should limit themselves
to the and modes, and the and options. On systems that support
getopt_long(), additional long options are available to improve compatibility
with other tar implementations.
Certain security issues are common
to many archiving programs, including In particular, carefully-crafted
archives can request that extract files to locations outside of the target
directory. This can potentially be used to cause unwitting users to overwrite
files they did not intend to overwrite. If the archive is being extracted
by the superuser, any file on the system can potentially be overwritten.
There are three ways this can happen. Although has mechanisms to protect
against each one, savvy users should be aware of the implications: Archive
entries can have absolute pathnames. By default, removes the leading character
from filenames before restoring them to guard against this problem. Archive
entries can have pathnames that include components. By default, will not
extract files containing components in their pathname. Archive entries
can exploit symbolic links to restore files to other directories. An archive
can restore a symbolic link to another directory, then use that link to
restore a file into that directory. To guard against this, checks each
extracted path for symlinks. If the final path element is a symlink, it
will be removed and replaced with the archive entry. If is specified, any
intermediate symlink will also be unconditionally removed. If neither nor
is specified, will refuse to extract the entry. To protect yourself,
you should be wary of any archives that come from untrusted sources. You
should examine the contents of an archive with before extraction. You should
use the option to ensure that will not overwrite any existing files or
the option to remove any pre-existing files. You should generally not extract
archives while running with super-user privileges. Note that the option
to disables the security checks above and allows you to extract an archive
while preserving any absolute pathnames, components, or symlinks to other
directories.
There is no current POSIX standard
for the tar command; it appeared in but was dropped from The options
used by this implementation were developed by surveying a number of existing
tar implementations as well as the old POSIX specification for tar and
the current POSIX specification for pax. The ustar and pax interchange
file formats are defined by for the pax command.
A command appeared
in Seventh Edition Unix, which was released in January, 1979. There have
been numerous other implementations, many of which extended the file format.
John Gilmore’s public-domain implementation (circa November, 1987) was quite
influential, and formed the basis of GNU tar. GNU tar was included as the
standard system tar in beginning with This is a complete re-implementation
based on the library.
This program follows for the definition of the
option. Note that GNU tar prior to version 1.15 treated as a synonym for
the option. The option may differ from historic implementations. All
archive output is written in correctly-sized blocks, even if the output
is being compressed. Whether or not the last output block is padded to a
full block size varies depending on the format and the output device. For
tar and cpio formats, the last block of output is padded to a full block
size if the output is being written to standard output or to a character
or block device such as a tape drive. If the output is being written to
a regular file, the last block will not be padded. Many compressors, including
and complain about the null padding when decompressing an archive created
by although they still extract it correctly. The compression and decompression
is implemented internally, so there may be insignificant differences between
the compressed output generated by and that generated by The default
should be to read and write archives to the standard I/O paths, but tradition
(and POSIX) dictates otherwise. The and modes require that the archive
be uncompressed and located in a regular file on disk. Other archives can
be modified using mode with the extension. To archive a file called
or you must specify it as or respectively. In create mode, a leading
is always removed. A leading is stripped unless the option is specified.
There needs to be better support for file selection on both create and
extract. There is not yet any support for multi-volume archives or for archiving
sparse files. Converting between dissimilar archive formats (such as tar
and cpio) using the convention can cause hard link information to be lost.
(This is a consequence of the incompatible ways that different archive
formats store hardlink information.) There are alternative long options
for many of the short options that are deliberately not documented.
Table of Contents