pax
[-cdnv][-H|-L][-f archive][-s replstr]...[pattern...]
pax -r[-cdiknuv][-H|-L][-f archive][-o options]...[-p string]...
[-s replstr]...[pattern...]
pax -w[-dituvX][-H|-L][-b blocksize][[-a][-f archive][-o options]...
[-s replstr]...[-x format][file...]
pax -r -w[-diklntuvX][-H|-L][-p string]...[-s replstr]...
[file...] directory
The pax utility shall read, write, and write lists of the members of archive files and copy directory hierarchies. A variety of archive formats shall be supported; see the -x format option.
The action to be taken depends on the presence of the -r and -w options. The four combinations of -r and -w are referred to as the four modes of operation: list, read, write, and copy modes, corresponding respectively to the four forms shown in the SYNOPSIS section.
If an attempt is made to extract a directory when the directory already exists, this shall not be considered an error. If an attempt is made to extract a FIFO when the FIFO already exists, this shall not be considered an error.
The ownership, access, and modification times, and file mode of the restored files are discussed under the -p option.
If no file operands are specified, a list of files to copy, one per line, shall be read from the standard input. A file of type directory shall include all of the files in the file hierarchy rooted at the file.
The effect of the copy shall be 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. If the destination directory is a subdirectory of one of the files to be copied, the results are unspecified. If the destination directory is a file of a type not defined by the System Interfaces volume of IEEE Std 1003.1-2001, the results are implementation-defined; otherwise, it shall be an error for the file named by the directory operand not to exist, not be writable by the user, or not be a file of type directory.
In read or copy modes, if intermediate directories are necessary to extract an archive member, pax shall perform actions equivalent to the mkdir() function defined in the System Interfaces volume of IEEE Std 1003.1-2001, called with the following arguments:
If any specified pattern or file operands are not matched by at least one file or archive member, pax shall write a diagnostic message to standard error for each one that did not match and exit with a non-zero exit status.
The archive formats described in the EXTENDED DESCRIPTION section shall be automatically detected on input. The default output archive format shall be implementation-defined.
A single archive can span multiple files. The pax utility shall determine, in an implementation-defined manner, what file to read or write as the next file.
If the selected archive format supports the specification of linked files, it shall be an error if these files cannot be linked when the archive is extracted. For archive formats that do not store file contents with each name that causes a hard link, if the file that contains the data is not extracted during this pax session, either the data shall be restored from the original file, or a diagnostic message shall be displayed with the name of a file that can be used to extract the data. In traversing directories, pax shall detect infinite loops; that is, entering a previously visited directory that is an ancestor of the last file visited. When it detects an infinite loop, pax shall write a diagnostic message to standard error and shall terminate.
The pax utility shall conform to the Base Definitions volume of IEEE Std 1003.1-2001, Section 12.2, Utility Syntax Guidelines, except that the order of presentation of the -o, -p, and -s options is significant.
The following options shall be supported:
The results of extracting a hard link to a file that has been renamed during extraction are unspecified.
keyword[[:]=value][,keyword[[:]=value], ...]
Some keywords apply only to certain file formats, as indicated with each description. Use of keywords that are inapplicable to the file format being processed produces undefined results.
Keywords in the options argument shall be a string that would be a valid portable filename as described in the Base Definitions volume of IEEE Std 1003.1-2001, Section 3.276, Portable Filename Character Set.
Keywords are not expected to be filenames, merely to follow the same character composition rules as portable filenames.
Keywords can be preceded with white space. The value field shall consist of zero or more characters; within value, the application shall precede any literal comma with a backslash, which shall be ignored, but preserves the comma as part of value. A comma as the final character, or a comma followed solely by white space as the final characters, in options shall be ignored. Multiple -o options can be specified; if keywords given to these multiple -o options conflict, the keywords and values appearing later in command line sequence shall take precedence and the earlier shall be silently ignored. The following keyword values of options shall be supported for the file formats as indicated:
(Applicable only to the -x pax format.) When used in write or copy mode, pax shall omit from extended header records that it produces any keywords matching the string pattern. When used in read or list mode, pax shall ignore any keywords matching the string pattern in the extended header records. In both cases, matching shall be performed using the pattern matching notation described in Patterns Matching a Single Character and Patterns Matching Multiple Characters . For example:
-o delete=security.*
would suppress security-related information. See pax Extended Header for extended header record keyword usage.
(Applicable only to the -x pax format.) This keyword allows user control over the name that is written into the ustar header blocks for the extended header produced under the circumstances described in pax Header Block . The name shall be the contents of string, after the following character substitutions have been made:
Any other ’%’ characters in string produce undefined results.
If no -o exthdr.name= string is specified, pax shall use the following default value:
%d/PaxHeaders.%p/%f
(Applicable only to the -x pax format.) When used in write or copy mode with the appropriate options, pax shall create global extended header records with ustar header blocks that will be treated as regular files by previous versions of pax. This keyword allows user control over the name that is written into the ustar header blocks for global extended header records. The name shall be the contents of string, after the following character substitutions have been made:
Any other ’%’ characters in string produce undefined results.
If no -o globexthdr.name= string is specified, pax shall use the following default value:
$TMPDIR/GlobalHead.%p.%n
where $ TMPDIR represents the value of the TMPDIR environment variable. If TMPDIR is not set, pax shall use /tmp.
(Applicable only to the -x pax format.) This keyword allows user control over the action pax takes upon encountering values in an extended header record that, in read or copy mode, are invalid in the destination hierarchy or, in list mode, cannot be written in the codeset and current locale of the implementation. The following are invalid values that shall be recognized by pax:
The following mutually-exclusive values of the action argument are supported:
In read or copy mode, pax shall bypass the file, causing no change to the destination hierarchy. In list mode, pax shall write all requested valid values for the file, but its method for writing invalid values is unspecified.
In read or copy mode, pax shall act as if the -i option were in effect for each file with invalid filename or link name values, allowing the user to provide a replacement name interactively. In list mode, pax shall behave identically to the bypass action.
When used in read, copy, or list mode and a filename, link name, owner name, or any other field in an extended header record cannot be translated from the pax UTF-8 codeset format to the codeset and current locale of the implementation, pax shall use the actual UTF-8 encoding for the name.
In read or copy mode, pax shall write the file, translating or truncating the name, regardless of whether this may overwrite an existing file with a valid name. In list mode, pax shall behave identically to the bypass action.
If no -o invalid= option is specified, pax shall act as if -o invalid= bypass were specified. Any overwriting of existing files that may be allowed by the -o invalid= actions shall be subject to permission ( -p) and modification time ( -u) restrictions, and shall be suppressed if the -k option is also specified.
(Applicable only to the -x pax format.) In write mode, pax shall write the contents of a file to the archive even when that file is merely a hard link to a file whose contents have already been written to the archive.
This keyword specifies the output format of the table of contents produced when the -v option is specified in list mode. See List Mode Format Specifications . To avoid ambiguity, the listopt= format shall be the only or final keyword= value pair in a -o option-argument; all characters in the remainder of the option-argument shall be considered part of the format string. When multiple -o listopt= format options are specified, the format strings shall be considered a single, concatenated string, evaluated in command line order.
(Applicable only to the -x pax format.) When used in write or copy mode, pax shall include atime, ctime, and mtime extended header records for each file. See pax Extended Header File Times .
In addition to these keywords, if the -x pax format is specified, any of the keywords and values defined in pax Extended Header, including implementation extensions, can be used in -o option-arguments, in either of two modes:
When used in write or copy mode, these keyword/value pairs shall be included at the beginning of the archive as typeflag g global extended header records. When used in read or list mode, these keyword/value pairs shall act as if they had been at the beginning of the archive as typeflag g global extended header records.
When used in write or copy mode, these keyword/value pairs shall be included as records at the beginning of a typeflag x extended header for each file. (This shall be equivalent to the equal-sign form except that it creates no typeflag g global extended header records.) When used in read or list mode, these keyword/value pairs shall act as if they were included as records at the end of each extended header; thus, they shall override any global or file-specific extended header record keywords of the same names. For example, in the command:
pax -r -o " gname:=mygroup, " <archive
the group name will be forced to a new value for all files read from the archive.
The precedence of -o keywords over various fields in the archive is described in pax Extended Header Keyword Precedence .
Do not preserve file access times.
Preserve the user ID, group ID, file mode bits (see the Base Definitions volume of IEEE Std 1003.1-2001, Section 3.168, File Mode Bits), access time, modification time, and any other implementation-defined file characteristics.
Do not preserve file modification times.
Preserve the user ID and group ID.
Preserve the file mode bits. Other implementation-defined file mode attributes may be preserved.
In the preceding list, "preserve" indicates that an attribute stored in the archive shall be given to the extracted file, subject to the permissions of the invoking process. The access and modification times of the file shall be preserved unless otherwise specified with the -p option or not stored in the archive. All attributes that are not preserved shall be determined as part of the normal file creation action (see File Read, Write, and Creation ).
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 shall not set the S_ISUID and S_ISGID bits of the file mode.
If the preservation of any of these items fails for any reason, pax shall write a diagnostic message to standard error. Failure to preserve these items shall affect the final exit status, but shall 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 shall take precedence. For example, if -p eme is specified, file modification times are preserved.
-s /old/new/[gp]
where as in ed, old is a basic regular expression and new can contain an ampersand, ’\n’ (where n is a digit) backreferences, or subexpression matching. The old string shall also be permitted to contain <newline>s.
Any non-null character can be used as a delimiter ( ’/’ shown here). Multiple -s expressions can be specified; the expressions shall be applied in the order specified, terminating with the first successful substitution. The optional trailing ’g’ is as defined in the ed utility. The optional trailing ’p’ shall cause successful substitutions to be written to standard error. File or archive member names that substitute to the empty string shall be ignored when reading and writing archives.
The cpio interchange format; see the EXTENDED DESCRIPTION section. The default blocksize for this format for character special archive files shall be 5120. Implementations shall support all blocksize values less than or equal to 32256 that are multiples of 512.
The pax interchange format; see the EXTENDED DESCRIPTION section. The default blocksize for this format for character special archive files shall be 5120. Implementations shall support all blocksize values less than or equal to 32256 that are multiples of 512.
The tar interchange format; see the EXTENDED DESCRIPTION section. The default blocksize for this format for character special archive files shall be 10240. Implementations shall support all blocksize values less than or equal to 32256 that are multiples of 512.
Implementation-defined formats shall specify a default block size as well as any other block sizes supported for character special archive files.
Any attempt to append to an archive file in a format different from the existing archive format shall cause pax to exit immediately with a non-zero exit status.
In copy mode, if no -x format is specified, pax shall behave as if -x pax were specified.
The options that operate on the names of files or archive members ( -c, -i, -n, -s, -u, and -v) shall interact as follows. In read mode, the archive members shall be selected based on the user-specified pattern operands as modified by the -c, -n, and -u options. Then, any -s and -i options shall modify, in that order, the names of the selected files. The -v option shall write names resulting from these modifications.
In write mode, the files shall be selected based on the user-specified pathnames as modified by the -n and -u options. Then, any -s and -i options shall modify, in that order, the names of these selected files. The -v option shall write names resulting from these modifications.
If both the -u and -n options are specified, pax shall not consider a file selected unless it is newer than the file to which it is compared.
In list mode with the -o listopt= format option, the format argument shall be applied for each selected file. The pax utility shall append a <newline> to the listopt output for each selected file. The format argument shall be used as the format string described in the Base Definitions volume of IEEE Std 1003.1-2001, Chapter 5, File Format Notation, with the exceptions 1. through 5. defined in the EXTENDED DESCRIPTION section of printf, plus the following exceptions:
- *
- Any of the Field Name entries in ustar Header Block and Octet-Oriented cpio Archive Entry . The implementation may support the cpio keywords without the leading c_ in addition to the form required by Values for cpio c_mode Field .
- *
- Any keyword defined for the extended header in pax Extended Header .
- *
- Any keyword provided as an implementation-defined extension within the extended header defined in pax Extended Header .
For example, the sequence "%(charset)s" is the string value of the name of the character set in the extended header.
The result of the keyword conversion argument shall be the value from the applicable header field or extended header, without any trailing NULs.
All keyword values used as conversion arguments shall be translated from the UTF-8 encoding to the character set appropriate for the local file system, user database, and so on, as applicable.
%b %e %H:%M %Y
(keyword[,keyword] ... )
The values for all the keywords that are non-null shall be concatenated together, each separated by a ’/’ . The default shall be ( path) if the keyword path is defined; otherwise, the default shall be ( prefix, name).
"%s -> %s", <value of keyword>, <contents of link>
Otherwise, the %L conversion specification shall be the equivalent of %F .
The following operands shall be supported:
In write mode, the standard input shall be used only if no file operands are specified. It shall be a text file containing a list of pathnames, one per line, without leading or trailing <blank>s.
In list and read modes, if -f is not specified, the standard input shall be an archive file.
Otherwise, the standard input shall not be used.
The input file named by the archive option-argument, or standard input when the archive is read from there, shall be a file formatted according to one of the specifications in the EXTENDED DESCRIPTION section or some other implementation-defined format.
The file /dev/tty shall be used to write prompts and read responses.
The following environment variables shall affect the execution of pax:
Determine the locale for the behavior of ranges, equivalence classes, and multi-character collating elements used in the pattern matching expressions for the pattern operand, the basic regular expression for the -s option, and the extended regular expression defined for the yesexpr locale keyword in the LC_MESSAGES category.
Default.
In write mode, if -f is not specified, the standard output shall be the archive formatted according to one of the specifications in the EXTENDED DESCRIPTION section, or some other implementation-defined format (see -x format).
In list mode, when the -o listopt= format has been specified, the selected archive members shall be written to standard output using the format described under List Mode Format Specifications . In list mode without the -o listopt= format option, the table of contents of the selected archive members shall be written to standard output using the following format:
"%s\n", <pathname>
If the -v option is specified in list mode, the table of contents of the selected archive members shall be written to standard output using the following formats.
For pathnames representing hard links to previous members of the archive:
"%s == %s\n", <ls -l listing>, <linkname>
For all other pathnames:
"%s\n", <ls -l listing>
where <ls -l listing> shall be the format specified by the ls utility with the -l option. When writing pathnames in this format, it is unspecified what is written for fields for which the underlying archive format does not have the correct information, although the correct number of <blank>-separated fields shall be written.
In list mode, standard output shall not be buffered more than a line at a time.
If -v is specified in read, write, or copy modes, pax shall write the pathnames it processes to the standard error output using the following format:
"%s\n", <pathname>
These pathnames shall be written as soon as processing is begun on the file or archive member, and shall be flushed to standard error. The trailing <newline>, which shall not be buffered, is written when the file has been read or written.
If the -s option is specified, and the replacement string has a trailing ’p’, substitutions shall be written to standard error in the following format:
"%s >> %s\n", <original pathname>, <new pathname>
In all operating modes of pax, optional messages of unspecified format concerning the input archive format and volume number, the number of files, blocks, volumes, and media parts as well as other diagnostic messages may be written to standard error.
In all formats, for both standard output and standard error, it is unspecified how non-printable characters in pathnames or link names are written.
When pax is in read mode or list mode, using the -x pax archive format, and a filename, link name, owner name, or any other field in an extended header record cannot be translated from the pax UTF-8 codeset format to the codeset and current locale of the implementation, pax shall write a diagnostic message to standard error, shall process the file as described for the -o invalid= option, and then shall process the next file in the archive.
In read mode, the extracted output files shall be of the archived file type. In copy mode, the copied output files shall be the type of the file being copied. In either mode, existing files in the destination hierarchy shall be overwritten only when all permission ( -p), modification time ( -u), and invalid-value ( -o invalid=) tests allow it.
In write mode, the output file named by the -f option-argument shall be a file formatted according to one of the specifications in the EXTENDED DESCRIPTION section, or some other implementation-defined format.
A pax archive tape or file produced in the -x pax format shall contain a series of blocks. The physical layout of the archive shall be identical to the ustar format described in ustar Interchange Format . Each file archived shall be represented by the following sequence:
At the end of the archive file there shall be two 512-byte blocks filled with binary zeros, interpreted as an end-of-archive indicator.
A schematic of an example archive with global extended header records and two actual files is shown in pax Format Archive Example . In the example, the second file in the archive has no extended header preceding it, presumably because it has no need for extended attributes.
The pax header block shall be identical to the ustar header block described in ustar Interchange Format, except that two additional typeflag values are defined:
For both of these types, the size field shall be the size of the extended header records in octets. The other fields in the header block are not meaningful to this version of the pax utility. However, if this archive is read by a pax utility conforming to the ISO POSIX-2:1993 standard, the header block fields are used to create a regular file that contains the extended header records as data. Therefore, header block field values should be selected to provide reasonable file access to this regular file.
A further difference from the ustar header block is that data blocks for files of typeflag 1 (the digit one) (hard link) may be included, which means that the size field may be greater than zero. Archives created by pax -o linkdata shall include these data blocks with the hard links.
A pax extended header contains values that are inappropriate for the ustar header block because of limitations in that format: fields requiring a character encoding other than that described in the ISO/IEC 646:1991 standard, fields representing file attributes not described in the ustar header, and fields whose format or length do not fit the requirements of the ustar header. The values in an extended header add attributes to the following file (or files; see the description of the typeflag g header block) or override values in the following header block(s), as indicated in the following list of keywords.
An extended header shall consist of one or more records, each constructed as follows:
"%d %s=%s\n", <length>, <keyword>, <value>
The extended header records shall be encoded according to the ISO/IEC 10646-1:2000 standard (UTF-8). The <length> field, <blank>, equals sign, and <newline> shown shall be limited to the portable character set, as encoded in UTF-8. The <keyword> and <value> fields can be any UTF-8 characters. The <length> field shall be the decimal length of the extended header record in octets, including the trailing <newline>.
The <keyword> field shall be one of the entries from the following list or a keyword provided as an implementation extension. Keywords consisting entirely of lowercase letters, digits, and periods are reserved for future standardization. A keyword shall not include an equals sign. (In the following list, the notations "file(s)" or "block(s)" is used to acknowledge that a keyword affects the following single file after a typeflag x extended header, but possibly multiple files after typeflag g. Any requirements in the list for pax to include a record when in write or copy mode shall apply only when such a record has not already been provided through the use of the -o option. When used in copy mode, pax shall behave as if an archive had been created with applicable extended header records and then extracted.)
The encoding is included in an extended header for information only; when pax is used as described in IEEE Std 1003.1-2001, it shall not translate the file data into any other encoding. The BINARY entry indicates unencoded binary data.
When used in write or copy mode, it is implementation-defined whether pax includes a charset extended header record for a file.
When used in write or copy mode, pax shall include a path extended header record for each file whose pathname cannot be represented entirely with the members of the portable character set other than NUL.
If the <value> field is zero length, it shall delete any header block field, previously entered extended header value, or global extended header value of the same name.
If a keyword in an extended header record (or in a -o option-argument) overrides or deletes a corresponding field in the ustar header block, pax shall ignore the contents of that header block field.
Unlike the ustar header block fields, NULs shall not delimit <value>s; all characters within the <value> field shall be considered data for the field. None of the length limitations of the ustar header block fields in ustar Header Block shall apply to the extended header records.
This section describes the precedence in which the various header records and fields and command line options are selected to apply to a file in the archive. When pax is used in read or list modes, it shall determine a file attribute in the following sequence:
The pax utility shall write an mtime record for each file in write or copy modes if the file’s modification time cannot be represented exactly in the ustar header logical record described in ustar Interchange Format . This can occur if the time is out of ustar range, or if the file system of the underlying implementation supports non-integer time granularities and the time is not an integer. All of these time records shall be formatted as a decimal representation of the time in seconds since the Epoch. If a period ( ’.’ ) decimal point character is present, the digits to the right of the point shall represent the units of a subsecond timing granularity, where the first digit is tenths of a second and each subsequent digit is a tenth of the previous digit. In read or copy mode, the pax utility shall truncate the time of a file to the greatest value that is not greater than the input header file time. In write or copy mode, the pax utility shall output a time exactly if it can be represented exactly as a decimal number, and otherwise shall generate only enough digits so that the same time shall be recovered if the file is extracted on a system whose underlying implementation supports the same time granularity.
A ustar archive tape or file shall contain a series of logical records. Each logical record shall be a fixed-size logical record of 512 octets (see below). Although this format may be thought of as being stored on 9-track industry-standard 12.7 mm (0.5 in) magnetic tape, other types of transportable media are not excluded. Each file archived shall be represented by a header logical record that describes the file, followed by zero or more logical records that give the contents of the file. At the end of the archive file there shall be two 512-octet logical records filled with binary zeros, interpreted as an end-of-archive indicator.
The logical records may be grouped for physical I/O operations, as described under the -b blocksize and -x ustar options. Each group of logical records may be written with a single operation equivalent to the write() function. On magnetic tape, the result of this write shall be a single tape physical block. The last physical block shall always be the full size, so logical records after the two zero logical records may contain undefined data.
The header logical record shall be structured as
shown in the following table. All lengths and offsets are in decimal.
| All characters in the header logical record shall be represented in |
| the coded character set of the ISO/IEC 646:1991 |
| standard. For maximum portability between implementations, names should |
| be selected from characters represented by the portable |
| filename character set as octets with the most significant bit zero. |
| If an implementation supports the use of characters outside of |
| slash and the portable filename character set in names for files, |
| users, and groups, one or more implementation-defined encodings |
| of these characters shall be provided for interchange purposes. |
| However, the pax utility shall never create filenames on the |
| local system that cannot be accessed via the procedures |
| described in IEEE Std 1003.1-2001. If a filename is found on the |
| medium that would create an invalid filename, it is |
| implementation-defined whether the data from the file is stored on |
| the file hierarchy and under what name it is stored. The |
| pax utility may choose to ignore these files as long as it produces |
| an error indicating that the file is being ignored. |
| Description |
| T} |
| 04000 S_ISUID T{ |
| Set UID on execution. |
| T} |
| 02000 S_ISGID T{ |
| Set GID on execution. |
| T} |
| 01000 <reserved> T{ |
| Reserved for future standardization. |
| T} |
| 00400 S_IRUSR T{ |
| Read permission for file owner class. |
| T} |
| 00200 S_IWUSR T{ |
| Write permission for file owner class. |
| T} |
| 00100 S_IXUSR T{ |
| Execute/search permission for file owner class. |
| T} |
| 00040 S_IRGRP T{ |
| Read permission for file group class. |
| T} |
| 00020 S_IWGRP T{ |
| Write permission for file group class. |
| T} |
| 00010 S_IXGRP T{ |
| Execute/search permission for file group class. |
| T} |
| 00004 S_IROTH T{ |
| Read permission for file other class. |
| T} |
| 00002 S_IWOTH T{ |
| Write permission for file other class. |
| T} |
| 00001 S_IXOTH T{ |
| Execute/search permission for file other class. |
| T} |
| For each file in the archive, a header as defined previously shall |
| be written. The information in the header fields is written |
| as streams of the ISO/IEC 646:1991 standard characters interpreted |
| as octal numbers. The octal numbers shall be extended to |
| the necessary length by appending the ISO/IEC 646:1991 standard IRV |
| zeros at the most-significant-digit end of the number; the |
| result is written to the most-significant digit of the stream of octets |
| first. The fields shall be interpreted as follows: |