The pax command writes files to archive files, reads them or creates lists of these files and copies directory hierarchies. A number of archive formats are supported; see the -x
format option.
The action executed depends on which of the -r and -w options are specified. The four possible combinations of -r and -w give the four operating modes: list mode, read mode, write mode, and copy mode, corresponding respectively to the four forms shown in the Syntax.
list
In list mode (i.e. neither -r nor -w is specified), pax reads an archive file from the standard input and writes the name of the stored files, whose pathnames match the specified pattern, to the standard output. If a specified file is a directory, the file hierarchy rooted at that file will be written out also.
read
In read mode (i.e. -r is specified, but not -w), pax reads an archive file from the standard input and extracts the files whose pathnames match the specified pattern. If the extracted file is a directory, the file hierarchy rooted at that file is also extracted. The extracted files are created relative to the current directory.
write
In write mode (i.e. -w is specified, but not -r), pax writes the contents of the file operands to the standard output in archive format. If no file operand is specified, a list of files to copy, one per line, is read from the standard input. When specifying a directory, all files in the file hierarchy rooted at that file are copied.
copy
In copy mode (i.e. both -r and -w are specified), pax copies the file operands to the destination directory directory.
If no file operands are specified, a list of all files to be copied, one per line, is read from the standard input. When specifying a directory, all files in the file hierarchy rooted at that file are copied.
The copying process runs as if the copied files were written to an archive file and subsequently extracted, except that there may be hard links between the original and the copied files.
If temporary directories are needed to extract a file in read or copy mode, these are created by pax.
At least one file must match the specified pattern or file operands, otherwise pax writes a diagnostic message to the standard message output for each operand that is unmatched, and terminates with a non-zero exit status.
The archive formats supported are automatically recognized when reading the file. The standard output format for archives when writing (no -x option specified) is the extended tar format.
An archive can span multiple files. The pax command determines what file to read or write as the next file.
If the selected archive format supports the specification of links between files, pax returns an error if no link can be created between these files during extraction.
Syntax
Format 1: |
pax[ -cdnv][ -f archive][ -s instruction] ... [pattern...] |
Format 2: |
pax -r[ -cdiknuv][ -f archive][ -p string] ... [ -s instruction] ... [pattern ...] |
Format 3: |
pax -w[ -dituvX][ -b blocksize][ -a][ -f archive] [ -s instruction] ... [ -x format][file ...] |
Format 4: |
pax -r -w[ -diklntuvX][ -p string] ... [ -s instruction] ... [file ...] directory |
options
Reads an archive file from the standard input.
Writes files in the specified archive format to the standard input.
Appends files to the end of the archive.
Puts the data in blocks in the archive file, and specifies the block size as a positive decimal integer. Devices and archive formats may impose restrictions on blocking. Blokking is automatically determined on input. Default blocking during the creation of archives depends on the archive format (see the -x option below). To maintain a portable archive, the block size may not be bigger than 32 KB.
Selects all files apart from those specified by the pattern or file operands.
The file hierarchy rooted at this file in a directory is not copied, read, or archived.
Specifies the pathname of the input archive (in list or read mode) or the output archive (write mode). This archive is used instead of the standard input or output.
Renames files interactively. For every file archived whose name matches the pattern operand, or for every file that matches a file operand, a prompt is written to
Prevents the overwriting of existing files.
Creates links between files. Hard links are created whenever possible between source and target file hierarchies.
Selects the first file archived that matches the pattern operand. Only one matching file is selected for every pattern operand (file hierarchies rooted at the directories are not affected by this restriction).
Determines file characteristics (privileges). The string argument contains the file characteristics that must be retained or ignored during extraction. The string consists of the a, e, m, o and p specification characters. Several characters can be concatenated in the same string, and the -p option can be specified more than once.
In the list above, "preserved" means that an attribute saved in the archive will be assigned to the extracted file, depending on the privileges of the invoking process. Otherwise, the attribute is defined as part of the normal file creation action. pax does not set the s bits for the file mode. If for any reason, one of these attributes cannot be preserved, pax writes a diagnostic message to the standard output. If an attribute cannot be preserved, the extracted file is not deleted, although it does effect the exit status. If specification characters are duplicated in the string argument or are in conflict with the other arguments, the last argument entered has priority. If for example -p
Modifies files specified by the pattern or file operands, according to the instruction . The syntax of ed is used for this. The concepts "address" and "line" mean nothing in the context of the pax command. The following format is used: As in ed, old is a simple regular expression and new can contain & signs, \n (where \n is a number), references, and subexpressions. The old string can also contain a newline character. All characters can be used as delimiters (e.g. /). A number of -s expressions are allowed. The expressions are evaluated in the specified order ending with the first successful substitution. The optional trailing g is as defined in ed.
The date and time of the last access to archived files are set to the value they had before being accessed by pax.
Ignores files that are an older version (with an older last modification date/time) of a file of the same name that already exists. In read mode, an archived file that has the same name as a file in the file system is extracted if the archived file is more current than theone in the file system. A file is only saved in write mode if there is no more recent version with the same name.
In list mode, a detailed table of contents is written to the standard output. Otherwise the pathnames of the stored file are written to the standard output.
Specifies the archive output format. pax recognizes the following formats:
The extended cpio interchange format. The default block size for this character-oriented archive file format is 512. Implementations of pax support all values for the block size up to 32256 that are a multiple of 512.
The extended tar interchange format. The default block size for this character-oriented archive file format is 1024. Implementations of pax support all values for the block size up to 32256 that are a multiple of 512. pax terminates immediately with a non-zero exit status if an attempt is made to append data to an archive file in a different format than the existing archive format.
pax will not switch to a directory in a different file system when traversing a file hierarchy specified by a pathname. The options that operate on the names of files (-c, -i, -n, -s, -u and -v) are evaluated one after the other as described below: In read mode, the files are selected according to pattern operands specified by the user, and the modifications made using the -c, -n and -u options. The -s and -i options in this order then modify the names of the selected files. The -v option outputs the names resulting from these modifications. In write mode, the files are selected according to pathnames specified by the user, and the modifications performed using the -n and -u options. The -s and -i options then modify the names of the selected files. The -v option outputs the names resulting from these modifications. If both the -u option and the -n option are specified, pax does not consider a file unless it is more current than the file to which it is compared.
Pathname of the target directory for copy mode.
Pathname of the file to be copied or archived.
A pattern that matches one or more pathnames of archived files. By default (if no pattern is specified), all files in the archive are selected. |
Standard input (stdin)
In write mode, the standard input is only used if no file operands are specified. The standard output must then be a text file containing a list of the pathnames. The file must contain one pathname per line, and there may be no preceding or trailing blank characters. In list and read mode, the standard input must be an archive file. Otherwise the standard input is not used. The input file specified by archive or the standard input if the archive is read from it, is a file formatted according to one of the archive formats listed in the -x option. Prompts are written and responses read to or from stdin/stdout. |
Standard output (stdout)
If -f is not specified in write mode, the standard output is the archive formatted according to one of the archive formats listed in the -x option. In list mode, the table of contents of the selected files are written to the standard output in the following format:
If -v is specified in list mode, the table of contents of the selected files is written to the standard output in the following format. Pathnames that represent hard links to previous files are written in this format:
All other pathnames are written in this format:
ls_-l_listing is the format created by the ls command with the -l option. |
Standard error (stderr)
If -v is specified in read, write or copy mode, pax writes the pathnames it processes to the standard error output in thefollowing format:
These pathnames are output at the start of file processing. The final newline character is output after the file is read or written. If the -s option is specified, and there is a trailing p in the substitution string, substitutions are written to the standard error output in the following format:
Any messages about the archive format are also written to the standard error output. |
Output files
In read mode, the files extracted or copied are of the archived file type. In write mode, the output file named by the -f option is a file formatted according to archive formats listed in the -x option. |
Consequence errors
If pax cannot create a file or a link when reading an archive, cannot find a file when writing an archive, or cannot preserve the user ID, group ID, or access rights with the -p option set, a diagnostic message is written to the standard error output and a non-zero exit status is returned. Processing is continued nonetheless. If pax cannot create a link to a file, by default it does not create a second copy of the file. If the extraction of a file from an archive is prematurely ended by a signal or an error, pax may only have extracted a part of the file, or (if the -n option is not specified) a file under the name specified by the user, that is not the file the user wanted. Extracted directory access rights may also have additional bits from the file-creation mode mask as well as incorrect information about the date and time of the last file access and modification. |
Locale
The following environment variables affect the execution of pax: LANG Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined. LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_COLLATE Determines the locale for the behavior of ranges, equivalence classes and collating elements used in the pattern matching expressions for the pattern operand, in the simple regular expression for the -s option, and in the extended regular expression defined for yes/no queries. LC_CTYPE Determines the locale for the interpretation of byte sequences (e.g. single-byte as opposed to multibyte characters in arguments and input files), for the behavior of character classes used in the extended regular expressions defined for yes/no queries, and for pattern matching. LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. LC_TIME Determines the format and the content of date and time specifications if the -v option is specified. NLSPATH Determine the location of message catalogs for the processing of LC_MESSAGES. |
Hint
This hint is only for users who have created archives in a Unix system using the Unix tar and cpio commands. The -p option was introduced to reconcile differences between the conventional tar and cpio implementations. In particular these two commands use -m in very different ways. The -p option also provides extended facilities for the consistent addressing of future file attributes, e.g. for extended security systems or high performance archives. Of the many combinations, only two modes are usually used:
"Preserve everything" is used by the conventional superuser with all the appropriate privileges to preserve all file attributes as they are recorded in the archive. The e flag is the sum of o and p.
"Preserve" the access rights. This is used by users with regular privileges who would like to preserve all file attributes apart from the owner. The file date and time specifications are preserved by default. However this can be deactivated with two other flags, and the date and time of extraction used. Some of the functionalities described require appropriate privileges for whoever calls pax, particularly when creating block-oriented or character-oriented special files, when restoring the date and time of file access (-t option), provided that the user is not the owner of the file, or when preserving the group, and the mode (-p option). |
Example
The following command creates an archived named archiv containing the files file1 through filen plus the directory dir1 and all its subdirectories:
The following commands copy the olddir file hierarchy to newdir:
The following command reads the a.pax archive, whereby all file directories/files rooted in
|