Linux and Unix pax command

Quick links

About pax
Syntax
Examples
Related commands
Linux and Unix main page

About pax

Short for portable archive interchange, the pax command reads, writes, and writes lists of the members of archive files and copy directory hierarchies.

Syntax

pax [-c] [-d] [-n] [-v] [-f archive] [-s replstr] [pattern]
pax -r [-c] [-d] [-i] [-k] [-n] [-u] [-v] [-f archive] [ -o options] 
    [-p string] [-s replstr] [pattern]
pax -w [-d] [-i] [-t] [-u] [-v] [-X] [-b blocksize] [-a] i [-f archive] 
    [-o options] [-s replstr] [-x format] [file]
pax -r -w [-d] [-i] [-k] [-l] [-n] [-t] [-u] [-v] [-X] [-p string] 
    [-s replstr] [file] directory
-c Match all file or archive members except those specified by the pattern or file operands.
-d Cause files of type directory being copied or archived or archive members of type directory being extracted to match only the file or archive member itself and not the file hierarchy rooted at the file.
-n Select the first archive member that matches each pattern operand. No more than one archive member will be matched for each pattern (although members of type directory will still match the file hierarchy rooted at that file).
-v In list mode, produce a verbose table of contents (see Standard Output). Otherwise, write archive member path names to standard error (see Standard Error).
-r Read an archive file from standard input.
-i Interactively rename files or archive members. For each archive member matching a pattern operand or file matching a file operand, a prompt will be written to the file /dev/tty. The prompt will contain the name of the file or archive member. A line will then be read from /dev/tty. If this line is blank, the file or archive member will be skipped. If this line consists of a single period, the file or archive member will be processed with no modification to its name. Otherwise, its name will be replaced with the contents of the line. The pax command will immediately exit with a non-zero exit status if end-of-file is encountered when reading a response or if /dev/tty cannot be opened for reading and writing.
-k Prevent the overwriting of existing files.
-l Link files. In copy mode, hard links will be made between the source and destination file hierarchies whenever possible.
-u Ignore files that are older (having a less recent file modification time) than a pre-existing file or archive member with the same name.

read mode an archive member with the same name as a file in the file system will be extracted if the archive member is newer than the file.
write mode an archive file member with the same name as a file in the file system will be superseded if the file is newer than the archive member.
copy mode the file in the destination hierarchy will be replaced by the file in the source hierarchy or by a link to the file in the source hierarchy if the file in the source hierarchy is newer.
-t Cause the access times of the archived files to be the same as they were before being read by pax.
-X When traversing the file hierarchy specified by a path name, pax will not descend into directories that have a different device ID (st_dev).
-w Write files to the standard output in the specified archive format.
-a Append files to the end of the archive. This option will not work for some archive devices, such as 1/4-inch streaming tapes and 8mm tapes.
-f archive Specify the path name of the input or output archive, overriding the default standard input (in list or read modes) or standard output (write mode).
-s replstr Modify file or archive member names named by pattern or file operands according to the substitution expression replstr, which is based on the ed s (substitution) command, using the regular expression syntax on the regex manual page. The concepts of "address" and "line" are meaningless in the context of the pax command, and must not be supplied. The format is:

-s/old/new/[gp]

where, as in ed, old is a basic regular expression and new can contain an ampersand ("&") or a "\n" backreference, where n is a digit. The old string also is permitted to contain newline characters.

Any non-null character can be used as a delimiter ( "/" is shown here). Multiple -s expressions can be specified; the expressions will be applied in the order specified, terminating with the first successful substitution. The optional trailing g is as defined in the ed command. The optional trailing p causes successful substitutions to be written to standard error. File or archive member names that substitute to the empty string are ignored when reading and writing archives.

-b blocksize Block the output at a positive decimal integer number of bytes per write to the archive file. Devices and archive formats may impose restrictions on blocking. Blocking is automatically determined on input. Portable applications must not specify a blocksize value larger than 32256. Default blocking when creating archives depends on the archive format. (See the -x option below.)
-o options Reserved for special format-specific options.
-p string Specify one or more file characteristic options (privileges). The string option-argument must be a string specifying file characteristics to be retained or discarded on extraction. The string consists of the specification characters a, e, m, o, and p. Multiple characteristics can be concatenated within the same string and multiple -p options can be specified. The meaning of the specification characters are as follows:

a Do not preserve file access times.
e Preserve the user ID, group ID, file mode bits, access time, and modification time.
m Do not preserve file modification times.
o Preserve the user ID and group ID.
p Preserve the file mode bits. Other, implementation-dependent file-mode attributes may be preserved.

In the preceding list, "preserve" indicates that an attribute stored in the archive will be given to the extracted file, subject to the permissions of the invoking process; otherwise, the attribute will be 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 setuid and setgid bits of the file mode.

If the preservation of any of these items fails for any reason, 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 file-characteristic letters in any of the string option-arguments are duplicated or conflict with each other, the ones given last will take precedence. For example, if -p eme is specified, file modification times will be preserved.

-x format Specify the output archive format. The pax command recognizes the following formats:

cpio The extended cpio interchange format; see the IEEE 1003.1(1990) specifications. The default blocksize for this format for character special archive files is 5120. Implementations support all blocksize values less than or equal to 32256 that are multiples of 512.

This archive format allows files with UIDs and GIDs up to 262143 to be stored in the archive. Files with UIDs and GIDs greater than this value will be archived with the UID and GID of 60001.
ustar The extended tar interchange format; see the IEEE 1003.1(1990) specifications. The default blocksize for this format for character special archive files is 10240. Implementations support all blocksize values less than or equal to 32256 that are multiples of 512.

Any attempt to append to an archive file in a format different from the existing archive format will cause pax to exit immediately with a non-zero exit status.

This archive format allows files with UIDs and GIDs up to 2097151 to be stored in the archive. Files with UIDs and GIDs greater than this value will be archived with the UID and GID of 60001.
pattern A pattern matching one or more path names of archive members. A pattern must conform to the pattern matching notation found on the fnmatch manual page. The default, if no pattern is specified, is to select all members in the archive.
file A path name of a file to be copied or archived.
directory The destination directory path name for copy mode.

Examples

pax -w -f /dev/rmt/1m

Copies the contents of the current directory to tape drive 1, medium density.

Related commands

chmod
cpio
ed
tar