tar - tape file archiver
tar [-]key [arg ...] [file | -C directory] ...
The tar command saves and restores archives of files on a magnetic
tape, a flexible disk, or a regular file. The default archive file is
/dev/rmt/0m. See the -f option below. Its actions are controlled by
the key argument.
key is a string of characters containing exactly one
function letter and zero or more function modifiers,
specified in any order. Whitespace is not permitted in
key. The key string can be preceded by a hyphen (-), as
when specifying options in other HP-UX commands, but it
is not necessary.
arg ... The b and f function modifiers each require an arg
argument (see below). If both b and f are specified,
the order of the arg arguments must match the order of
the modifiers. If specified, the arg arguments must be
separated from the key and each other by whitespace.
file specifies a file being saved or restored. If file is a
directory name, it refers to the files and (recursively)
the subdirectories contained in that directory.
-C directory causes tar to perform a chdir() to directory (see
chdir(2)). Subsequent file and -C directory arguments
are relative to directory. This allows multiple
directories not related by a close or common parent to
be archived using short relative path names.
The value of file is stored in the archive. The value of directory is
The function portion of the key is specified by exactly one of the
c Create a new archive. Write from the beginning of the
archive instead of appending after the last file. Any
previous information in the archive is overwritten.
r Add the named file to the end of the archive. The same
blocking factor used to create the archive must be used to
append to it. This option cannot be used if the archive is a
Hewlett-Packard Company - 1 - HP-UX Release 11i: November 2000
t List the names of all the files in the archive. Adding the
v function modifier expands this listing to include the file
modes and owner numbers. The names of all files are listed
each time they occur on the tape.
u Add any named file to the archive if it is not already
present or has been modified since it was last written in
the archive. The same blocking factor used to create the
archive must be used to update it.
x Extract the named file from the archive and restore it to
the system. If a named file matches a directory whose
contents were written to the archive, this directory is
(recursively) extracted. If a named file on tape does not
exist on the system, the file is created as follows:
+ The user, group, and other protections are restored
from the tape.
+ The modification time is restored from the tape
unless the m function modifier is specified.
+ The file user ID and group ID are normally those of
the restoring process.
+ The set-user-ID, set-group-ID, and sticky bits are
not set automatically. The o and p function
modifiers control the restoration of protection; see
below for more details.
If the files exist, their modes are not changed, but the
set-user-id, set-group-id and sticky bits are cleared. If
no file argument is given, the entire content of the archive
is extracted. Note that if several files with the same name
are on the archive, the last one overwrites all earlier
Function Modifier Keys
The following function modifiers can be used in addition to the
function letters listed above (note that some modifiers are
incompatible with some functions):
A Suppress warning messages that tar did not archive a file's
access control list. By default, tar writes a warning
message for each file with optional ACL entries.
b Use the next arg argument as the blocking factor for archive
records. The default is 20; the maximum is at least 20.
However, if the f - modifier is used to specify standard
input, the default blocking factor is 1.
Hewlett-Packard Company - 2 - HP-UX Release 11i: November 2000
The blocking factor is determined automatically when reading
nine-track tapes (key letters x and t). On nine-track
tapes, the physical tape record length is the same as the
block size. The block size is defined as the logical record
size times the blocking factor (number of logical records
The blocking factor must be specified when reading flexible
disks and cartridge tapes if they were written with a
blocking factor other than the default.
If a tar file is read using a blocking factor not equal to
the one used when the file was written, an error may occur
at the end of the file but there may or may not be an actual
error in the read. To prevent this problem, a blocking
factor of 1 can be used, although performance may be reduced
tar writes logical records of 512 bytes, independent of how
logical records may be defined elsewhere by other programs
(such as variable-length records (lines) within an ASCII
e Fail if the extent attributes are present in the files to be
archived. If tar fails for this reason, the partially
created destination file is not be removed.
f Use the next arg argument as the name of the archive instead
of the default, /dev/rmt/0m. If the name of the file is -,
tar writes to standard output or reads from standard input,
whichever is appropriate, and the default blocking factor
becomes 1. Thus, tar can be used as the head or tail of a
pipeline (see EXAMPLES).
h Force tar to follow symbolic links as if they were normal
files or directories. Normally, tar does not follow
l Tell tar to complain if it cannot resolve all of the links
to the files being saved. If l is not specified, no error
messages are printed.
m Tell tar not to restore the modification time written on the
archive. The modification time of the file will be the time
N Write a POSIX format archive. This format allows file names
of up to 256 characters in length, and correctly archives
and restores the following file types: regular files,
character and block special devices, links, symbolic links,
directories, and FIFO special files. It also stores the
Hewlett-Packard Company - 3 - HP-UX Release 11i: November 2000
user and group name of each file and attempts to use these
names to determine the user-ID and group-ID of a file when
restoring it with the p function modifier. This is the
o Suppress writing certain directory information that older
versions of tar cannot handle on input. tar normally writes
information specifying owners and modes of directories in
the archive. Earlier versions of tar, when encountering
this information, give error messages of the form:
name - cannot create
When o is used for reading, it causes the extracted file to
take on the user and group IDs of the user running the
program rather than those on the tape. This is the default
for the ordinary user and can be overridden, to the extent
that system protections allow, by using the p function
O Write a pre-POSIX format archive.
p Cause file to be restored to the original modes and
ownerships written on the archive, if possible. This is the
default for the superuser, and can be overridden by the o
function modifier. If system protections prevent the
ordinary user from executing chown(), the error is ignored,
and the ownership is set to that of the restoring process
(see chown(2)). The set-user-id, set-group-id, and sticky
bit information are restored as allowed by the protections
defined by chmod() if the chown() operation above succeeds.
nd Specify a particular nine-track tape drive and density,
where n is a tape drive number: 0-7, and d is the density: l
= low (800 bpi); m = medium (1600 bpi); h = high (6250 bpi).
This modifier selects the drive on which the nine-track tape
is mounted. The default is 0m.
v Normally, tar does its work silently. The v (verbose)
function modifier causes tar to type the name of each file
it treats, preceded by the function letter. With the t
function, v gives more information about the archive entries
than just the name.
V Same as the v function modifier except that, when using the
t option, tar also prints out a letter indicating the type
of the archived file.
w Cause tar to print the action being taken, followed by the
name of the file, then wait for the user's confirmation. If
the user answers y, the action is performed. Any other
Hewlett-Packard Company - 4 - HP-UX Release 11i: November 2000
input means "no".
When end-of-tape is reached, tar prompts the user for a new special
file and continues.
If a nine-track tape drive is used as the output device, it must be
configured in Berkeley-compatibility mode (see mt(7)).
The O and N function modifiers specify the format in which tar writes
the archive. Upon extraction, tar can read either format, regardless
of the function modifiers used.
LC_TIME determines the format and contents of date and time strings
output when listing the contents of an archive with the -v option.
LANG determines the language equivalent of y (for yes/no queries).
If LC_TIME is not specified in the environment or is set to the empty
string, the value of LANG is used as the default.
If LANG is not specified or is set to the empty string, it defaults to
"C" (see lang(5)).
If any internationalization variable contains an invalid setting, tar
behaves as if all internationalization variables are set to "C". See
International Code Set Support
Single- and multibyte character code sets are supported.
tar issues self-explanatory messages about bad key characters, tape
read/write errors, and if not enough memory is available to hold the
Create a new archive on /dev/rfd.0 and copy file1 and file2 onto it,
using the default blocking factor of 20. The key is made up of one
function letter (c) and two function modifiers (v and f):
tar cvf /dev/rfd.0 file1 file2
Archive files from /usr/include and /etc:
tar cv -C /usr/include . -C /etc .
Use tar in a pipeline to copy the entire file system hierarchy under
fromdir to todir:
Hewlett-Packard Company - 5 - HP-UX Release 11i: November 2000
cd fromdir ; tar cf - . | ( cd todir ; tar xf - )
Archive all files and directories in directory my_project in the
current directory to a file called my_project.TAR, also in the current
tar -cvf my_project.TAR my_project
Because of industry standards and interoperability goals, tar does not
support the archival of files larger than 2GB or files that have
user/group IDs greater than 60K. Files with user/group IDs greater
than 60K are archived and restored under the user/group ID of the
The default format has changed from O to N, beginning with HP-UX
Due to internal limitations in the header structure, not all file
names of fewer than 256 characters fit when using the N function
modifier. If a file name does not fit, tar prints a message and does
not archive the file.
Link names are still limited to 100 characters when using the N
There is no way to ask for the n-th occurrence of a file.
Tape errors are handled ungracefully.
The u function key can be slow.
If the archive is a file on disk, flexible disk, or cartridge tape,
and if the blocking factor specified on output is not the default, the
same blocking factor must be specified on input, because the blocking
factor is not explicitly stored in the archive. Updating or appending
to the archive without following this rule can destroy it.
Some previous versions of tar have claimed to support the selective
listing of file names using the t function key with a list. This
appears to be an error in the documentation because the capability
does not appear in the original source code.
There is no way to restore an absolute path name to a relative
tar always pads information written to an archive up to the next
multiple of the block size. Therefore, if you are creating a small
archive and write out one block of information, tar reports that one
block was written, but the actual size of the archive might be larger
if the b function modifier is used.
Hewlett-Packard Company - 6 - HP-UX Release 11i: November 2000
Note that tar c0m is not the same as tar cm0.
Do not create archives on block special devices. Attempting to do so
can causes excessive wear, leading to premature drive hardware
The r and u function keys are not supported on QIC or 8mm devices. If
these options are used with QIC or 8mm devices, tar fails and displays
tar: option not supported for this device
tar was developed by AT&T, the University of California, Berkeley, HP,
ar(1), cpio(1), acl(5), mt(7).
tar: SVID2, SVID3, XPG2, XPG3
Hewlett-Packard Company - 7 - HP-UX Release 11i: November 2000