read write archives and copy directory hierarchies

list: pax [-0cdjnOvz] [-E limit] [-f archive] [-G group] [-s replstr] [-T range] [-U user] [pattern]

read: pax -r [-0cDdijknOuvYZz] [-E limit] [-f archive] [-G group] [-o options] [-p string] [-s replstr] [-T range] [-U user] [pattern]

write: pax -w [-0adHijLOPtuvXz] [-B bytes] [-b blocksize] [-f archive] [-G group] [-o options] [-s replstr] [-T range] [-U user] [-x format] [file]

copy: pax -rw [-0DdHijkLlnOPtuvXYZ] [-G group] [-p string] [-s replstr] [-T range] [-U user] [file] directory

list, read, write members of an archive and copy directory hierarchies.


none List to standard output table of contents of members of the archive file from standard input, whose pathnames match the specified pattern arguments.
one filename per line using single line buffering.
-r Read: extracts members with pathnames matching the specified pattern arguments.
For directories, the entire file hierarchy rooted at that directory is extracted.
Extracted files are created either at absolute paths (those beginning with / ) or relative to the current file hierarchy
With -s removes leading slashes or add a relative path prefix.
Files extracted to absolute paths may overwrite files outside of the current working directory. For example /etc/passwd
-w Writes an archive to standard output of
file operands
a list of files one per line .
When an operand is a directory the hierarchy will be included.
-rw Copy to the destination directory the file operands
list of files to copy.
When a operand is a directory the file hierarchy will be included.
Effect is as if the copied files were written to an archive file and then subsequently extracted.
There may be hard links between the original and the copied files (see the -l option below).

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.

Continues after media defect errors (see -E )

It is an error If the directory operand specifies a destination directory pathname that does not exist, is not writable or is not a directory

The pattern selects pathnames of members as per glob.
When a pattern matches a directory, the file hierarchy at that directory will be selected.
It is a error if a pattern does not select at least one member

-0 Use the NUL (`\0') character as a pathname terminator, instead of newline (`\n').
When pathnames read from standard input in the write and copy modes, and to the pathnames written to standard output in list mode. Useful with find -print0 and xargs -0.
-a Append the files to the end of an existing archive
It is an error to attemp to change archive formats. The blocking size used in the archive volume where writing starts will continue to be used for the remainder of that archive volume. Warning: Some devices do not support append and may damage the archive or have unpredictable results. Tape drives in particular are more likely to not support an append operation.
-B bytes Limit the size of an archive to bytes.
Suffixes `m', `k', or `b' to specify multiplication by 1048576 (1M), 1024 (1K) or 512. A pair of bytes limits can be separated by `x' to indicate a product. For example 5xk : 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).
DO NOT use of this option with a floppy or hard disk.
-b blocksize When writing an archive, block the output at a positive decimal integer number of bytes per write to the archive file. The blocksize must be a multiple of 512 bytes with a maximum of 64512 bytes. Archive block sizes larger than 32256 bytes violate the POSIX standard and will not be portable to all systems. A blocksize can end with `k' or `b' to specify multiplication by 1024 (1K) or 512, respectively. A pair of blocksizes can be separated by `x' to 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 -x option).
-c Match all file or archive members except those specified by the pattern and file operands.
-d Cause files of type directory being copied or archived, or archive members of type directory being extracted, to match only the directory file or archive member and not the file hierarchy rooted at the directory.
-E limit Limit the number of consecutive read faults while trying to read a flawed archive to limit. With a positive limit, pax will 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 pax to stop operation after the first read error is detected on an archive volume. A limit of NONE will cause pax to 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.
-f archive Specify archive as the pathname of the input or output archive, overriding the default standard input (for list and read) or standard output (for write). A single archive may span multiple files and different archive devices. When required, pax will prompt for the pathname of the file or device of the next volume in the archive.
-G group Select a file based on its group name, or when starting with a #, a numeric GID. A `\' can be used to escape the #. Multiple -G options may be supplied and checking stops with the first match.
-H Follow only command-line symbolic links while performing a physical file system traversal.
-i Interactively rename files or archive members. For each archive member matching a pattern operand or each file matching a file operand, pax will prompt to /dev/tty giving the name of the file, its file mode, and its modification time. pax will 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. pax will 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.
-j Use bzip2 to compress (decompress) the archive while writing (reading). The bzip2 utility must be installed separately. Incompatible with -a.
-k Do not overwrite existing files.
-L Follow all symbolic links to perform a logical file system traversal.
-l Link files. In the copy mode (-r -w), hard links are made between the source and destination file hierarchies whenever possible.
-n Select the first archive member that matches each pattern operand. No more than one archive member is matched for each pattern. When members of type directory are matched, the file hierarchy rooted at that directory is also matched (unless -d is also specified).
-O Force the archive to be one volume. If a volume ends prematurely, pax will not prompt for a new volume. This option can be useful for automated tasks where error recovery cannot be performed by a human.
-o options Information to modify the algorithm for extracting or writing archive files which is specific to the archive format specified by -x. In general, options take the form: name=value. The following options are available for the old BSD tar format: nodir write_opt=nodir When writing archives, omit the storage of directories.
-P Do not follow symbolic links, perform a physical file system traversal. This is the default mode.
-p string Specify one or more file characteristic options (privileges). The string option-argument is 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 meanings of the specification characters are as follows:
a Do not preserve file access times. By default, file access times are preserved whenever possible.
e "Preserve everything", the user ID, group ID, file mode bits, file access time, and file modification time. This is intended to be used by root, someone with all the appropriate privileges, in order to preserve all aspects of the files as they are recorded in the archive. The e flag is the sum of the o and p flags.
m Do not preserve file modification times. By default, file modification times are preserved whenever possible.
o Preserve the user ID and group ID.
p "Preserve" the file mode bits. This is intended to be used by a user with regular privileges who wants to preserve all aspects of the file other than the ownership. The file times are preserved by default, but two other flags are offered to disable this and use the time of extraction instead.
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 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 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 -p eme is specified, file modification times are still preserved.
-r Read an archive file from standard input and extract the specified file operands. 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 OR of S_IRWXU, S_IRWXG, and S_IRWXO as 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, pax will write a diagnostic message to standard error and exit with a non-zero exit status at the completion of operation.
-s replstr Modify the archive member names according to the substitution expression replstr, using the syntax of the ed(1) utility regular expressions. file or pattern arguments may be given to restrict the list of archive members to those specified. The 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:
original-pathname >> new-pathname

File or archive member names that substitute to the empty string are not selected and will be skipped.

-T range Allow files to be selected based on a file modification or inode change time falling within the specified time range. The range has the format:

The dates specified by from_date to to_date are inclusive. If only a from_date is supplied, all files with a modification or inode change time equal to or younger are selected. If only a to_date is supplied, all files with a modification or inode change time equal to or older will be selected. When the from_date is equal to the to_date, only files with a modification or inode change time of exactly that time will be selected.

in 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 be archived).

A time range is made up of six different fields and each field must contain two digits. The format is: [[[[[cc]yy]mm]dd]HH]MM[.SS] Where cc is the first two digits of the year (the century), yy is the last two digits of the year, the first mm is the month (from 01 to 12), dd is the day of the month (from 01 to 31), HH is the hour of the day (from 00 to 23), MM is the minute (from 00 to 59), and SS is the seconds (from 00 to 59). The minute field MM is required, while the other fields are optional and must be added in the following order: HH, dd, mm, yy, cc.

The SS field may be added independently of the other fields. Time ranges are relative to the current time, so -T 1234/cm would select all files with a modification or inode change time of 12:34 PM today or later. Multiple -T time range can be supplied and checking stops with the first match.

-t set the access times of any file or directory accessed to the same as they were before being accessed
-U user Select a file based on its user name, or (when starting with a #) a numeric UID.
Use \ to escape the #.
Warning: UID do not necessarily specify the same user on different systems. Multiple -U options may be supplied. Checking stops with the first match.
-D as with -u , except that the file change time is checked instead of the modification time. The change time can be used to select files whose information (e.g., UID, GID, etc.) is newer than a copy of the file in the destination directory.
-Y as with -D except that the change time is checked using the pathname created after all the file name modifications have completed.
-u Ignore files older (having a less recent file modification time) than a existing file or archive member with the same name.
During read, an archive member will be extracted if it is newer than an existing file.
During write, a file system file will replace a memeber if it is newer .
During copy, the file in the destination hierarchy is 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.
-Z as -u except that the modification time is checked using the pathname created after all the file name modifications have completed.
-v During a list operation, verbose as produce by ls -l.
For hard link to a previous member of the archive, the output has the format:
              ls -l listing == link-name

For pathnames representing a symbolic link, the output has the format:

ls -l listing => link-name
Pathnames are written and flushed to standard error without a trailing newline when processing begins. The trailing newline is written after the file has been proessed.
-w Write files to the standard output in the specified archive format. When no file operands are specified, standard input is read for a list of pathnames with one per line without any leading or trailing .
-X do not descend into directories that have a different device ID. See the st_dev field as described in stat(2)
-x format archive format, default ustar.
ustar extended tar (IEEE Std 1003.2 ("POSIX.2") standard). The default blocksize 10240, Filenames must be less than 101 characters ; the total pathname must be less than 256
cpio The extended cpio interchange format specified in the IEEE Std 1003.2 ("POSIX.2") standard. The default blocksize 5120 .
sv4cpio The System V release 4 cpio. default blocksize 5120 bytes.
sv4crc The System V release 4 cpio with file CRC checksums. The default blocksize 5120
tar BSD tar format 4.3BSD. default blocksize 10240 . Pathnames must less than 101 characters. Only regular files, hard links, soft links, and directories are supported.
-o when writing an archive omits the storage of directories. This option takes the form:
-o write_opt=nodir

Files that cannot be stored or extracted as the result of archive restrictions are reported.

-z Use gzip(1) to compress (decompress) the archive. Incompatible with -a.
--insecure Normally ignores filenames or symbolic links that contain ".." as a path component. With this option, files that contain ".." can be processed.

Options that operate on the names (-c, -i, -j, -n, -s, -u, -v, -D, -G, -T, -U, -Y, and -Z) interact.

When extracting files, archive members are selected, based on the specified pattern operands as modified by -c, -n, -u, -D, -G, -T, -U .
Then -s and -i will modify in that order, the names of these selected files.
Then -Y and -Z will be applied based on the final pathname.
Finally, -v will write the resulting name.

When archiving or copying files, archive members are `selected', based on the specified pathnames as modified by -n, -u, -D, -G, -T, and -U(-D only applies during a copy ).
Then -s and -i will modify in that order, the names of these selected files.
Then during a copy -Y and -Z will be applied based on the final pathname.
Finally, -v will write the resulting names.

When -u or -D are specified with -n , a file is not selected unless it is newer than the file to which it is compared.


$TMPDIR Path in which to store temporary files.


Copy the contents of the current directory to the device /dev/rst0: $ pax -w -f /dev/rst0 . Give the verbose table of contents for an archive stored in filename: $ pax -v -f filename This sequence of commands will copy the entire olddir directory hierarchy to newdir: $ mkdir newdir $ cd olddir $ pax -rw . ../newdir Extract files from the archive a.pax. Files rooted in /usr are extracted relative to the current working directory; all other files are extracted to their unmodified path. $ pax -r -s ',^/usr/,,' -f a.pax This can be used to interactively select the files to copy from the current directory to dest_dir: $ pax -rw -i . dest_dir Extract all files from the archive a.pax which are owned by root with group bin and preserve all file permissions: $ pax -r -pe -U root -G bin -f a.pax Update (and list) only those files in the destination directory /backup which are older (less recent inode change or file modification times) than files with the same name found in the source file tree home: $ pax -r -w -v -Y -Z home /backup DIAGNOSTICS 0 All files were processed successfully. 1 An error occurred. Whenever 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 written to 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 pax completes it will exit with a non-zero exit status.


cpio(1), tar(1) "Archiving with Pax", Dru Lavigne, BSD DevCenter,

pax(1) manual page, compliant with the IEEE Std 1003.1-2004 ("POSIX.1") specification. -0BDEGHjLOPTUYZz, the archive formats bcpio, sv4cpio, sv4crc, tar, and the flawed archive handling during list and read operations are extensions to that specification.