| TAR(1) | General Commands Manual | TAR(1) |
tar — tape
archiver
tar |
{crtux}[014578abefHhJjLmOoPpqsvwXZz]
[blocking-factor | archive |
replstr] [-C
directory] [-I
file] [file ...] |
tar |
{-crtux}
[-014578aeHhJjLmOoPpqvwXZz]
[-b blocking-factor]
[-C directory]
[-D format-options]
[-f archive]
[-I file]
[-M flag]
[-s replstr]
[file ...] |
The tar command creates, adds files to, or
extracts files from an archive file in “tar” (strictly
speaking, ustar) format. A tar archive is often
stored on a magnetic tape, but can be stored equally well on a floppy,
CD-ROM, or in a regular disk file.
In the first (legacy) form, all option flags except for
-C and -I must be contained
within the first argument to tar and must not be
prefixed by a hyphen (‘-’). Option arguments, if any, are
processed as subsequent arguments to tar and are
processed in the order in which their corresponding option flags have been
presented on the command line.
In the second and preferred form, option flags may be given in any order and are immediately followed by their corresponding option argument values.
One of the following flags must be present:
-c-r-ttar will list all archive members that match
each pattern.-u-r.-xtar will extract all archive members
that match each pattern.
If more than one copy of a file exists in the archive, later copies will overwrite earlier copies during extraction. The file mode and modification time are preserved if possible. The file mode is subject to modification by the umask(2).
In addition to the flags mentioned above, any of the following flags may be used:
-atar; it is
strongly recommended to archive to stdout and pipe into an external
compression utility with appropriate arguments instead:
tar -cf - foo | xz -2e
>foo.txz-b
blocking-factortar
uses 512-byte blocks. The default is 20, the maximum is 126. Archives with
a blocking factor larger than 63 violate the POSIX standard and will not
be portable to all systems.-C
directory-D
format-optionstar currently supports the following formats and
options:
arbcpiotar
and is repaired.cpiotar and is repaired.sv4cpiotar and is
repaired.sv4crctar and is repaired.tarFor backwards compatibility with even older tar formats,
the write_opt=nodir option can be used when
writing an archive to omit the storage of directories.
ustartar will detect and report any file
that it is unable to store or extract as the result of any specific
archive format restrictions. The individual archive formats may impose
additional restrictions on use. Typical archive format restrictions
include (but are not limited to): file pathname length, file size, link
pathname length, and the type of the file.
-e-f
archiveTAPE
environment variable.-H-h-I
file-J-j-L-h option.-M
flagroot:wheel).
When creating an archive and verbosely listing output, these normalisation operations are not reflected in the output, because they are made only after the output has been shown.
This option is only implemented for the ar, cpio, sv4cpio, sv4crc, and ustar file format writing routines.
-m-O-otar is unable to decode. Same as
-D tar,write_opt=nodir.-Ptar skips pathnames
containing dotdot (“..”) components and strips leading
slashes (‘/’) from pathnames by default; this option
disables that behaviour.-p-x flag.-q-s
replstrThe format of these regular expressions is
/old/new/[gp]As in ed(1),
old is a basic regular expression (see
re_format(7)) and
new can contain an ampersand
(‘&’),
‘\n’ (where
n is a digit) back-references, or subexpression
matching. The old string may also contain newline
characters. Any non-null character can be used as a delimiter
(‘/’ is shown here). Multiple
-s expressions can be specified. The expressions
are applied in the order they are specified on the command line,
terminating with the first successful substitution.
The optional trailing g continues to
apply the substitution expression to the pathname substring, which
starts with the first character following the end of the last successful
substitution. The first unsuccessful substitution stops the operation of
the g option. The optional trailing
p will cause the final result of a successful
substitution to be written to standard error in the following
format:
File or archive member names that substitute to the empty string are not selected and will be skipped.
-v-v is specified
multiple times or if the -t option is also
specified, tar will use a long format for listing
files, similar to ls(1)
-l.-wtar
to prompt the user for the filename to use when storing or extracting
files in an archive.-X-Z-zThe options [-014578] can be used to
select one of the compiled-in backup devices,
/dev/rstN.
The tar utility exits with one of the
following values:
Create an archive on the default tape drive, containing the files named bonvole and sekve:
$ tar c bonvole sekveOutput a gzip(1) compressed archive containing the files bonvole and sekve to a file called foriru.tar.gz:
$ tar zcf foriru.tar.gz bonvole
sekveVerbosely create an archive, called backup.tar.gz, of all files matching the shell glob(7) function *.c:
$ tar zcvf backup.tar.gz
*.cVerbosely list, but do not extract, all files ending in .jpeg from a compressed archive named backup.tar.gz. Note that the glob pattern has been quoted to avoid expansion by the shell:
$ tar tvzf backup.tar.gz
'*.jpeg'For more detailed examples, see pax(1).
Whenever tar cannot create a file or a
link when extracting an archive or cannot find a file while writing an
archive, or cannot preserve the user ID, group ID, file mode, or access and
modification times when the -p option is specified,
a diagnostic message is written to standard error and a non-zero exit value
will be returned, but processing will continue. In the case where
tar cannot create a link to a file, unless
-M lncp is given,
tar will not create a second copy of the file.
If the extraction of a file from an archive is prematurely
terminated by a signal or error, tar may have only
partially extracted the file the user wanted. Additionally, the file modes
of extracted files and directories may have incorrect file bits, and the
modification and access times may be wrong.
If the creation of an archive is prematurely terminated by a
signal or error, tar may have only partially created
the archive, which may violate the specific archive format
specification.
A tar command first appeared in
Version 7 AT&T UNIX.
Keith Muller at the University of California, San Diego. MirBSD extensions by mirabilos ⟨m@mirbsd.org⟩.
The flags -aDJjLMo are not portable to
other implementations of tar where they may have a
different meaning or not exist at all.
This implementation may have support for other non-standard options that are undocumented because removal-inducing deprecation was issued.
The pax file format is not yet supported.
| January 5, 2024 | MirBSD |