|PAX(1)||General Commands Manual||PAX(1)|
pax — read and
write file archives and copy directory hierarchies
pax will read, write, and list the members
of an archive file, and will copy directory hierarchies. If the archive file
is of the form: [[user@]host:]file then the archive
will be processed using
pax operation is independent of the
specific archive format, and supports a wide variety of different archive
formats. A list of supported archive formats can be found under the
description of the
The presence of the
-r and the
-w options specifies which of the following
pax will operate under:
list, read, write, and
paxwill write to
standard outputa table of contents of the members of the archive file read from
standard input, whose pathnames match the specified patterns. The table of contents contains one filename per line and is written using single line buffering.
paxextracts the members of the archive file read from the
standard input, with pathnames matching the specified patterns. The archive format and blocking is automatically determined on input. When an extracted file is a directory, the entire file hierarchy rooted at that directory is extracted. All extracted files are created relative to the current file hierarchy. The setting of ownership, access and modification times, and file mode of the extracted files are discussed in more detail under the
paxwrites an archive containing the file operands to
standard outputusing the specified archive format. When no file operands are specified, a list of files to copy with one per line is read from
standard input. When a file operand is also a directory, the entire file hierarchy rooted at that directory will be included.
paxcopies the file operands to the destination directory. When no file operands are specified, a list of files to copy with one per line is read from the
standard input. When a file operand is also a directory the entire file hierarchy rooted at that directory will be included. The effect of the copy is as if the copied files were written to an archive file and then subsequently extracted, except that there may be hard links between the original and the copied files (see the
Warning: The destination directory must not be one of the file operands or a member of a file hierarchy rooted at one of the file operands. The result of a copy under these conditions is unpredictable.
While processing a damaged archive during a read
or list operation,
attempt to recover from media defects and will search through the archive to
locate and process the largest number of archive members possible (see the
-E option for more details on error handling).
The directory operand specifies a
destination directory pathname. If the directory
operand does not exist, or it is not writable by the user, or it is not of
pax will exit with a non-zero exit
The pattern operand is used to select one or
more pathnames of archive members. Archive members are selected using the
pattern matching notation described by
fnmatch(3). When the
pattern operand is not supplied, all members of the
archive will be selected. When a pattern matches a
directory, the entire file hierarchy rooted at that directory will be
selected. When a pattern operand does not select at
least one archive member,
pax will write these
pattern operands in a diagnostic message to
standard error and then exit with a non-zero exit
The file operand specifies the pathname of a
file to be copied or archived. When a file operand
does not select at least one archive member,
will write these file operand pathnames in a
diagnostic message to
standard error and then exit
with a non-zero exit status.
The following options are supported:
standard inputand extract the specified files. If any intermediate directories are needed in order to extract an archive member, these directories will be created as if mkdir(2) was called with the bitwise inclusive
S_IRWXOas the mode argument. When the selected archive format supports the specification of linked files and these files cannot be linked while the archive is being extracted,
paxwill write a diagnostic message to
standard errorand exit with a non-zero exit status at the completion of operation.
standard outputin the specified archive format. When no file operands are specified,
standard inputis read for a list of pathnames with one per line without any leading or trailing ⟨blanks⟩.
-xoption, the format currently being used in the archive will be selected. Any attempt to append to an archive in a format different from the format already used in the archive will cause
paxto exit immediately with a non-zero exit status. The blocking size used in the archive volume where writing starts will continue to be used for the remainder of that archive volume.
Warning: Many storage devices are not able to support the operations necessary to perform an append operation. Any attempt to append to an archive stored on such a device may damage the archive or have other unpredictable results. Tape drives in particular are more likely to not support an append operation. An archive stored in a regular file system file or on a disk device will usually support an append operation.
bto specify multiplication by 1024 (1K) or 512, respectively. A pair of blocksizes can be separated by
xto indicate a product. A specific archive device may impose additional restrictions on the size of blocking it will support. When blocking is not specified, the default blocksize is dependent on the specific archive format being used (see the
standard input(for list and read) or
standard output(for write). A single archive may span multiple files and different archive devices. When required,
paxwill prompt for the pathname of the file or device of the next volume in the archive.
paxwill prompt to /dev/tty giving the name of the file, its file mode and its modification time.
paxwill then read a line from /dev/tty. If this line is blank, the file or archive member is skipped. If this line consists of a single period, the file or archive member is processed with no modification to its name. Otherwise, its name is replaced with the contents of the line.
paxwill immediately exit with a non-zero exit status if ⟨
EOF⟩ is encountered when reading a response or if /dev/tty cannot be opened for reading and writing.
-w), hard links are made between the source and destination file hierarchies whenever possible.
-dis also specified).
-x. In general, options take the form:
p. Multiple characteristics can be concatenated within the same string and multiple
-poptions can be specified. The meaning of the specification characters are as follows:
eflag is the sum of the
In the preceding list, ‘preserve’ indicates that
an attribute stored in the archive is given to the extracted file,
subject to the permissions of the invoking process. Otherwise the
attribute of the extracted file is determined as part of the normal file
creation action. If neither the
e nor the
o specification character is specified, or the
user ID and group ID are not preserved for any reason,
pax will not set the
S_ISUID (setuid) and
S_ISGID (setgid) bits of the
file mode. If the preservation of any of these items fails for any
pax will write a diagnostic message to
standard error. Failure to preserve these items
will affect the final exit status, but will not cause the extracted file
to be deleted. If the file characteristic letters in any of the string
option-arguments are duplicated or conflict with each other, the one(s)
given last will take precedence. For example, if
oldis a basic regular expression and
newcan contain an ampersand (&), \n (where n is a digit) back-references, or subexpression matching. The
oldstring may also contain ⟨
newline⟩ characters. Any non-null character can be used as a delimiter (/ is shown here). Multiple
-sexpressions 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
gcontinues 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
goption. The optional trailing
pwill cause the final result of a successful substitution to be written to
standard errorin the following format:
⟨original pathname⟩ >> ⟨new pathname⟩
paxto be the same as they were before being read or accessed by
pax, if the user has the appropriate permissions required by utime(3).
-loption. For pathnames representing a hard link to a previous member of the archive, the output has the format:
⟨ls -l listing⟩ == ⟨link name⟩
Otherwise for all the other operational modes
(read, write, and
copy), pathnames are written and flushed to
standard error without a trailing
newline⟩ as soon as processing
begins on that file or archive member. The trailing
newline⟩, is not buffered, and is
written only after the file has been read or written.
A final summary of archive operations is printed after they have been completed.
paxcurrently supports the following formats:
paxand is repaired.
paxand is repaired.
paxand is repaired.
paxand is repaired.
-ooption can be used when writing an archive to omit the storage of directories. This option takes the form:
pax 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.
bto specify multiplication by 1048576 (1M), 1024 (1K) or 512, respectively. A pair of bytes limits can be separated by
xto indicate a product.
Warning: Only use this option when writing an archive to a device which supports an end of file read condition based on last (or largest) write offset (such as a regular file or a tape drive). The use of this option with a floppy or hard disk is not recommended.
-uoption, except that the file inode change time is checked instead of the file modification time. The file inode change time can be used to select files whose inode information (e.g. uid, gid, etc.) is newer than a copy of the file in the destination directory.
paxwill attempt to recover from an archive read error and will continue processing starting with the next file stored in the archive. A limit of 0 will cause
paxto stop operation after the first read error is detected on an archive volume. A limit of
paxto attempt to recover from read errors forever. The default limit is a small positive number of retries.
Warning: Using this option with
NONE should be used with extreme caution as
pax may get stuck in an infinite loop on a very
badly flawed archive.
#, a numeric gid. A '\' can be used to escape the
-Goptions may be supplied and checking stops with the first match.
standard inputas an mtree(8) ‘specfile’ specification, and write or copy only those items in the specfile.
If the file exists in the underlying file system, its permissions and modification time will be used unless specifically overridden by the specfile. An error will be raised if the type of entry in the specfile conflicts with that of an existing file. A directory entry that is marked ‘optional’ will not be copied (even though its contents will be).
Otherwise, the entry will be ‘faked-up’, and it is necessary to specify at least the following parameters in the specfile: type, mode, gname or gid, and uname or uid, device (in the case of block or character devices), and link (in the case of symbolic links). If time isn't provided, the current time will be used. A ‘faked-up’ entry that is marked ‘optional’ will not be copied.
-Uoptions, use the user database text file master.passwd and group database text file group from dbdir, rather than using the results from the system's getpwnam(3) and getgrnam(3) (and related) library calls.
paxwill not prompt for a new volume. This option can be useful for automated tasks where error recovery cannot be performed by a human.
pax is in the
write or copy mode, the optional
trailing field [c][m] can be used to determine
which file time (inode change, file modification or both) are used in
the comparison. If neither is specified, the default is to use file
modification time only. The m specifies the
comparison of file modification time (the time when the file was last
written). The c specifies the comparison of inode
change time (the time when the file inode was last changed; e.g. a
change of owner, group, mode, etc). When c and
m are both specified, then the modification and
inode change times are both compared. The inode change time comparison
is useful in selecting files whose attributes were recently changed or
selecting files which were recently created and had their modification
time reset to an older time (as what happens when a file is extracted
from an archive and the modification time is preserved). Time
comparisons using both file times is useful when
pax is used to create a time based incremental
archive (only files that were changed during a specified time range will
A time range is made up of six different fields and each field must contain two digits. The format is:
ccis the first two digits of the year (the century),
yyis the last two digits of the year, the first
mmis the month (from 01 to 12),
ddis the day of the month (from 01 to 31),
hhis the hour of the day (from 00 to 23), the second
mmis the minute (from 00 to 59), and
ssis the seconds (from 00 to 61). Only the minute field
mmis required; the others will default to the current system values. The
ssfield may be added independently of the other fields. If the century is not specified, it defaults to 1900 for years between 69 and 99, or 2000 for years between 0 and 68. Time ranges are relative to the current time, so
-Ttime range can be supplied and checking stops with the first match.
#, a numeric uid. A '\' can be used to escape the
-Uoptions may be supplied and checking stops with the first match.
st_devfield as described in stat(2) for more information about device ID's.
-Doption, except that the inode change time is checked using the pathname created after all the file name modifications have completed.
-uoption, except that the modification time is checked using the pathname created after all the file name modifications have completed.
paxignores filenames that contain “..” as a path component. With this option, files that contain “..” can be processed.
The options that operate on the names of files or archive members
-Z) interact as
When extracting files during a read operation,
archive members are ‘selected’, based only on the user
specified pattern operands as modified by the
-U options. Then any
-i options will
modify in that order, the names of these selected files. Then the
-Z options will be
applied based on the final pathname. Finally the
option will write the names resulting from these modifications.
When archiving files during a write operation,
or copying files during a copy operation, archive members
are ‘selected’, based only on the user specified pathnames as
modified by the
-U options (the
-D option only applies during a copy operation).
will modify in that order, the names of these selected files. Then during a
copy operation the
-Y and the
-Z options will be applied based on the final
pathname. Finally the
-v option will write the names
resulting from these modifications.
When one or both of the
-D options are specified along with the
-n option, a file is not considered selected unless
it is newer than the file to which it is compared.
pax will exit with one of the following
pax cannot create a file or a
link when reading an archive or cannot find a file when writing an archive,
or cannot preserve the user ID, group ID, or file mode when the
-p option is specified, a diagnostic message is
standard error and a non-zero exit status
will be returned, but processing will continue. In the case where pax cannot
create a link to a file,
pax 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,
pax may have only
partially extracted a 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,
pax may have only partially created
the archive which may violate the specific archive format specification.
If while doing a copy,
pax detects a file is about to overwrite itself, the
file is not copied, a diagnostic message is written to
standard error and when
completes it will exit with a non-zero exit status.
pax -w -f /dev/rst0 .
pax -v -f filename
The following commands:
pax -rw -pp . ../newdir
When running as root, one may also wish to preserve file ownership when copying directory trees. This can be done with the following commands:
pax -rw -pe . ../newdir
pax -r -s ',^//*usr//*,,' -f a.pax
pax -rw -i . dest_dir
pax -r -pe -U root -G bin -f a.pax
pax -r -w -v -Y -Z home /backup
pax utility is a superset of the
IEEE Std 1003.2 (“POSIX.2”) standard.
-z, the archive formats
sv4crc, tar, and the flawed
archive handling during list and
read operations are extensions to the POSIX
Keith Muller at the University of California, San Diego. Luke
|November 13, 2013||NetBSD-7.0.1|