tarUSTAR-compatible tape archiver to copy and back up files |
Command |
tar
-c
[#sbfNvwlzU
]
[blocking_factor]
[archivefile]
[-V
volpat]
[file...]
[-C
pathname]
[file...]
tar
-r
[#sbfNvwlzU
]
[blocking_factor]
[archivefile]
[-V
volpat]
[file...]
[-C
pathname]
[file...]
tar
-t
[#sbfNvzU
]
[blocking_factor]
[archivefile]
[-V
volpat]
[file ...]
tar
-x
[#sbfNvwpmozU
]
[blocking_factor]
[archivefile]
[-V
volpat]
[file ...]
tar
manipulates archives. An archive is a single file that
contains the complete contents of a set of other files; an archive preserves the
directory hierarchy that contained the original files, in a manner similar to
cpio
. The name tar
was derived from Tape ARchiver; however, you can use archives
with any medium, including diskettes.
This version of the tar
utility writes and reads the original
tar
format from UNIX systems as well as the USTAR format
defined by the POSIX (IEEE P1003.1) standards group.
tar
. You must specify one of these primary options as the
first character of an option string.
-c
creates an archive. This command writes each named file into a
newly-created archive. Directories recursively include all components. If
-
appears in place of any file name,
tar
reads the standard input for a list of files, one
per line. This allows other commands to generate lists of files for
tar
to archive.
-r
writes the named files to the end of the archive. It is possible to have more than one copy of a file in an archive using this method. To use this form of the command with a tape, it must be possible to backspace the tape.
-t
displays a table of contents. This display contains the names of all
the files in the archive, one per line. If you specify one or more
files on the command line, tar
prints only
those file names. Under the verbose (-v
) option, more
information about each archive member is printed, in a format similar to
that produced by ls
-l
.
-x
extracts files from an archive. tar
extracts each
named file to a file of the same name. If you do not specify any
files on the command line, tar
extracts all files in
the archive. This extraction restores all file system attributes as
controlled by other options.
tar
as a single string. For example, you might use -tv
, but not
separate them as in -t -v
. You may omit the leading dash
-
if you want. The only exceptions to the single string rule
for secondary options to tar
are -C
and
-V
; see below for a full explanation of the secondary
options.
-b
sets the number of blocks used for tape archive read/write operations
to blocking_factor. If you specify -b
, you must
specify a blocking_factor argument. When reading from the tape
archive, tar
automatically determines the blocking
factor by trying to read the largest legal blocking factor and using the
actual number read to be the blocking_factor. For UNIX
compatibility, the largest valid value for blocking_factor is 20
blocks; in USTAR mode, it is 60 blocks. If -b
comes
before -f
in the options string, the
blocking_factor must come before the filename. Note that
blocks are typically 512 bytes, although some tape drives support other
sizes.
-C
pathnameis an unusual option because it is specified in the middle of your
file list. When tar
encounters a
-C
pathname option while archiving files,
tar
treats pathname as the current directory
and treats all following entries in your file list (including
another -C
) as being relative to pathname.
-f
uses the archivefile for the tape archive rather than the
default device. If -f
is used, the archivefile
argument must be specified. If -f
comes before
-b
in the options string, the archivefile must
come before the blocking_factor. If archivefile is the
character -
, tar
uses the standard input
for reading and the standard output for writing archives.
sets the default archive file name to a specific tape unit number and
density. For a more general method, use the -f
option.
The # may be any digit between 0 and 7, inclusive, to select the
tape unit. The density selector s may be l
(low),
m
(medium), or h
(high). For finer control over
the density, use the -f
or -V
option with an archive name such as -f /dev/nmtdqic-150
; see
tape for information on SCSI tape device names.
-l
complains if all links are not resolved when adding files to the tape archive.
-m
does not restore a file's modification time stamp when extracting it
from an archive. By default, tar
restores the time
stamp from information contained in the archive.
-o
when extracting files, does not attempt to assign owner and group information to extracted files. With this option, most operating systems assign your owner and group information to extracted files by default.
-p
when extracting, preserves the three high-order file attribute bits,
exactly as in the archive. On UNIX and POSIX-compliant systems, they
indicate the set-user-ID, set-group-ID, and saved-text attributes; to use
-p
on these systems, you must have appropriate
privileges. When -p
is set, tar
ignores the UMASK and restores the modes exactly as in the archive.
-U
when creating a new tape archive with the -c
option, forces tar
to use the USTAR format. The
default format used when creating a new archive is the original UNIX
tar
format. When you do not specify
-c
, tar
determines whether or not
the tape archive is in USTAR format by reading it, so the
U
option does not affect file extraction.
tar
displays an error message for a UNIX
tar
format file containing a bad file name;
-U
suppresses this message and still extracts the data
if the file name is acceptable in USTAR format.
-v
displays each file name, along with the appropriate action key letter
(a
for add, x
for extract) as it processes the
archive. With the -t
form of the command, this option
gives more detail about each archive member being listed.
-V
volpatprovides automatic multi-volume support. tar
writes
output to files -- whose names are formatted using volpat. Any
occurrence of #
in volpat is replaced by the current
volume number. When you invoke tar
with this option,
it asks you to insert the appropriate disk and then hit return before it
proceeds with the operation. With this option set, tar
issues the same sort of message when a write error or read error occurs on
the archive. The reasoning is that this kind of error means that
tar
has reached the end of the volume and should go on
to a new one.
-w
is used to confirm each operation, such as replacing or extracting.
tar
displays the operation and the file involved.
You can then confirm whether or not you want the operation to take place.
Typing in an affirmative answer (in the POSIX locale, one that begins with
y
or Y
) tells tar
to do the
operation; anything else tells tar
to go on to the
next operation.
-z
performs compression. Output is at compression level 5. On input, any
compression level up to 9 is acceptable. In addition,
-z
expands compressed archives on input.
tar
uses the gzip format to compress files.
as the one command line:tar -cvf - directory | mkszip >archive
To identify all files that have been changed in the last week (7 days), and to archive them to a file on diskette, you might type:tar -cvzf archive directory
find directory -mtime -7 | tar -cvf a:archive -
0
Successful completion.
1
Failure due to any of the following:
The/dev/mt0
-U
option is an extension to provide POSIX
USTAR format compatibility.
The -p
option is a common extension on BSD UNIX systems that
is not available on UNIX System V systems.
These two options as well as the -C
, -V
,
and -z
options are extensions to the x/OPEN standard.
The -u
option specified in XPG is not currently supported.
tar
utility cannot save files larger than eight
gigabytes in size in an archive. However, other programs that extract files from
tar
archives may be unable to properly extract files larger
than two gigabytes and tar
issues a warning to that effect
when you attempt to save such a file.
stat