pax Command
Purpose
Extracts, writes, and lists members of archive files; copies files and directory hierarchies.
Syntax
- To List Member Files of Archived Files
-
pax [ -c | -n] [-d] [-U ] [ -v] [
-H
| -L ] [-f Archive] [ -s ReplacementString... ] [-x Format] [-o Options] [ -Z ] [Pattern... ] - To Extract Archive Files Using the -r Flag
-
pax -r [ -c | -n ] [ -d ] [ -i ] [ -k ] [ -U ] [ -u ] [ -v ] [
-H
|-L
] [ -f Archive] [ -o Options] [ -p String... ] [ -s ReplacementString... ] [ -x Format] [ -Z ] [Pattern ... ] - To Write Archive Files Using the -w Flag
-
pax -w [ -d ] [
- To Copy Files Using the -r and -w Flags
-
pax -r -w [ -d ] [ -i ] [ -k ] [ -l ] [ -t ] [ -U ] [ -u ] [ -v ] [ -X ] [ -H | -L ] [ -p String... ] [ -o Options] [ -s ReplacementString... ] [ -x Format] [ -Z ] [File ... ] Directory
Description
- Listing Member Files of Archived Files (List Mode)
-
When the -r flag or the -w flag is not specified, the pax command lists all the member files of the archive file that is read from standard input. If the Pattern parameter is specified, only the member files with path names that match the specified patterns are written to standard output. If a named file is a directory, the file hierarchy that is contained in the directory is also written. When the -r flag or the -w flag is not specified, the -c, -d, -f, -n, -s, and -v flags, and the Pattern parameter can be specified.
- Extracting Archive Files Using the -r Flag (Read Mode)
-
When the -r flag is specified, but the -w flag is not, the pax command extracts all the member files of the archive files that are read from standard input. If the Pattern parameter is specified, only the member files with path names that match the specified patterns are written to standard output. If a named file is a directory, the file hierarchy that is contained in the directory is also extracted. The -r flag can be specified with the -c, -d, -f, -i, -k, -n, -s, -u, and -v flags, and with the Pattern parameter.
The access and modification times of the extracted files are the same as the archived files. The file modes of the extracted files are the same as when they were archived, unless they are affected by the user's default file creation mode (
umask
). TheS_ISUID
andS_ISGID
bits of the extracted files are cleared.If intermediate directories are necessary to extract an archive member, the pax command creates the directories with access permissions set as the bitwise inclusive OR of the values of the
S_IRWXU
,S_IRWXG
, andS_IRWXO
masks.If the selected archive format supports the specification of linked files, it is an error if these files cannot be linked when the archive is extracted.
- Writing Archive Files Using the -w Flag (Write Mode)
-
When the -w flag is specified and the -r flag is not, the pax command writes the contents of the files that are specified by the File parameter to standard output in an archive format. If no File parameter is specified, a list of files to copy, one per line, is read from the standard input. When the File parameter specifies a directory, all of the files that are contained in the directory are written. The -w flag can be specified with the -a, -b, -d, -f, -i, -o, -s, -t, -u, -v, -x, and -X flags and with File parameters.
- Copying Files Using the -r and -w Flags (Copy Mode)
-
When both the -r and -w flags are specified, the pax command copies the files that are specified by the File parameters to the destination directory specified by the Directory parameter. If no files are specified, a list of files to copy, one per line, is read from the standard input. If a specified file is a directory, the file hierarchy that is contained in the directory is also copied. The -r and -w flags can be specified with the -d, -i, -k, -l, -o, -p, -s, -t, -u, -v, and -X flags and with File parameters. The Directory parameter must be specified.
Copied files are the same as written to an archive file and are later extracted, except that there are hard links between the original and the copied files.
- Modifying the Archive Algorithm Using the -o Flag
-
Use the -o flag to modify the archive algorithm according to keyword-value pairs. The keyword-value pairs must adhere to a correct archive format. A list of valid keywords and their behavior is given in the subsequent description of the -o flag.
- Further notes
-
In read or copy modes, if intermediate directories are necessary to extract an archive member, the pax command does actions similar to the
mkdir()
subroutine with the intermediate directory used as the path argument and the valueS_IRWXU
as the mode argument.If any specified pattern or file operands are not matched by at least one file or archive member, pax writes a diagnostic message to standard error for each one that did not match and exits with an error status.
In traversing directories, the pax command detects the infinite loops by entering a previously visited directory that is an ancestor of the last file visited. Upon detection of an infinite loop, the pax command writes a diagnostic message to standard error and terminates.
When pax command is in read mode or list mode, by using the -x pax archive format, a file name, link name, owner name, or any other field in an extended header record cannot be converted from the pax UTF8 code set format to the current code set and locale. The pax command writes a diagnostic message to standard error, processes the file as described for the -o invalid= option, and then processes the next file in the archive.
For AIX® 5.3 the pax command ignores the extended attributes by default. The -U option informs pax to archive or restore extended attributes, which include ACLs. The -pe option preserves ACLs. When the -pe option is specified and if pax fails to preserve the ACLs, a diagnostic message is written to the standard error but the extracted file is not deleted. A nonzero exit code is returned. A new record type is required for extended attribute entries in the pax archive files.
Variables
Item | Description |
---|---|
Directory | Specifies the path of a destination directory when copying files. |
File | Specifies the path of a file to be copied or archived. If no file matches the File parameter, the pax command detects the error, exits, and writes a diagnostic message. |
Pattern | Specifies a pattern that matches one or more paths of archive members. A / (backslash)
character is not recognized in the Pattern parameter and it prevents the subsequent character
from having any special meaning. If no Pattern parameter is specified, all members are
selected in the archive. If a Pattern parameter is specified, but no archive members are found that match the pattern that is specified, the pax command detects the error, exits, and writes a diagnostic message. |
Flags
Item | Description |
---|---|
-a | Appends files to the end of an archive. Note: Streaming tape devices do not allow the append
function.
|
-b Blocking | Specifies the block size for output. The Blocking parameter specifies a positive
decimal integer value that specifies the number of bytes per block. Application conforming to POSIX2
must not specify a blocksize value greater than 32256. Devices and archive formats might impose
restrictions on blocking. Blocking is automatically determined on input. Default blocking when the
archives are created depends on the archive format. (See the -x flag definition.) The Blocking parameter accepts one of the following values:
|
-c | Matches all file or archive members except the files that are specified by the Pattern parameter. |
-d | Causes directories being copied, archived, or extracted, to match the directory and not the contents of the directory. |
-E | Avoids truncation of the long user and group names during addition of files to a new or existing archive. |
-f Archive | Specifies the path of an archive file to be used instead of standard input (when the -w flag is not specified) or standard output (when the -w flag is specified but the -r flag is not). When specified with the -a flag option, any files that are written to the archive are appended to the end of the archive. |
-H | If a symbolic link that refers to a directory is specified on the command line, pax archives the file hierarchy that is rooted in the directory that is referenced in the link, by using the name of the link as the name of the file hierarchy. By default, pax archives the symbolic link itself. |
-i | Renames files or archives interactively. For each archive member that matches the Pattern parameter or file that matches a File parameter, a prompt is written to the display device that contains the name of a file or archive member. A line is then read from the display device. If this line is empty, 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. |
-k | Prevents the pax command from writing over existing files. |
-l | Links files when copying files. Hard links are established between the source and destination file hierarchies whenever possible. |
-L | If a symbolic link that refers to a directory is specified on the command line or encountered during the traversal of a file hierarchy, pax archives the file hierarchy that is rooted in the directory that is referenced in the link, by using the name of the link as the name of the file hierarchy. By default, pax archives the symbolic link itself. |
-n | Selects the first archive member that matches each Pattern parameter. No more than one archive member is matched for each pattern. |
-o Options | Modifies the archiving algorithm according to the keyword-value pairs specified in the
Options parameter. The keyword-value pairs must be in the following format: 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 will be ignored by pax. Keywords can be preceded with white space. The value field consists of zero or more characters; within value, any literal comma must be preceded with a backslash (\). A comma as the final character, or a comma that is followed by white space as the final character, in Options is ignored. Multiple -o options can be specified. If keywords given to these multiple -o options conflict, the keywords and values that appear later in the command-line sequences take precedence. The earlier values are ignored. The following keyword-value pairs are supported for the indicated file formats:
The Note: The
datastream keyword does not have a default variable size. You must
specify one.The Note: You can specify multiple instances of keyword pairs. If you assign different values to the
same keyword, the pax command uses the last value that is assigned to the keyword
to run the -o flag.
When used in write or copy mode, pax omits any keywords matching
pattern from the extended header records that it produces. When used in read or
list mode, pax ignores any keywords matching pattern in the
extended header records. In all cases, matching is done by using standard shell pattern-matching
notation. For example, |
Item | Description |
---|---|
-o Options (Continued) |
This keyword allows user control over the name that is written into the
Any other % characters in string produce undefined results. The pax
takes the default value of the name as
When used in write or copy
mode with the appropriate options, pax creates global extended
header records with
Any other % characters in string produce undefined results. If this keyword-value pair is not specified in the -o Options list, the default value of the name is
where
This keyword allows user control over the action pax takes upon encountering values in an extended header record that:
|
Item | Description |
---|---|
-o Options (Continued) | pax Recognizes these invalid values:
These mutually exclusive values of the action argument are supported:
In write mode, the pax command writes the contents of a file to the archive, even when that file is a hard link to a file whose contents are written to the archive. |
Item | Description |
---|---|
-o Options (Continued) |
This keyword specifies the output format of the table of contents that are produced when the
-v option is specified in list mode. To avoid ambiguity, this keyword-value
pair must be used as the only or final keyword-value pair following the -o
flag; all characters in the remainder of the option-argument are considered part of the format
string. If multiple -o listopt=format options are specified, the format strings
are considered to be a single, concatenated string, which is evaluated in command-line order. See
the
When used in write or copy mode, pax includes atime, ctime, and mtime extended header records for each file. |
- Extended header keywords
-
(Applicable only to the -x pax format.)
If the -x pax format is specified, the keywords and values that are defined in the following list can be used as parameters to the -o flag, in either of two modes:
- atime
-
The file access time for the following files, equivalent to the value of the st_atime member of the stat structure for a file.
- charset
-
The name of the character is set to encode the data in the following files. The entries in this table are defined to refer to known standards:
value Formal Standard ISO-IR 646 1990
ISO/IEC 646 IRV ISO-IR 8859 1 1987
ISO 8859-1 ISO-IR 8859 2 1987
ISO 8859-2 ISO-IR 10646 1993
ISO/IEC 10646 SO-IR 10646 1993 UTF8
ISO/IEC 10646, UTF8 encoding BINARY
None The encoding is included in an extended header for information only, when pax is used as described, it does not translate the file data into any other encoding. The BINARY entry indicates binary data that is not encoded.
comment
-
A series of characters that are used as a comment. All characters in the value field are ignored by pax.
ctime
-
The file creation time for the following file(s), equivalent to the value of the st_ctime member of the stat structure for a file.
gid
-
The group ID of the group that owns the file, expressed as a decimal number by using digits from ISO/IEC 646. This record overrides the gid field in the following header blocks. When used in write or copy mode, pax includes a gid extended header record for each file whose group ID is greater than 99,999,999.
gname
-
The group of the following files, formatted as a group name in the group database. This record overrides the gid and gname fields in the following header blocks, and any gid extended header record. When used in read, copy, or list mode, pax translates the name from the UTF8 encoding in the header record to the character set appropriate for the group database on the receiving system. If any of the UTF8 characters cannot be translated, and if the -o invalid=UTF8 option is not specified, the results are undefined. When used in write or copy mode, pax includes a gname extended header record for each file whose group name cannot be represented entirely with the letters and digits of the portable character set.
hdrcharset
-
The name of the character set that is used to encode the value field of the
gname
,linkpath
,path
, anduname
extended header records. The entries in the following table are defined to refer to the known standards. Extra names might be agreed between the originator and the recipient.If thevalue Formal Standard ISO-IR106462000UTF-8
ISO/IEC 10646, UTF-8 encoding BINARY
None hdrcharset
extended header record is not specified, the default character set (ISO/IEC 10646-1:2000 standard UTF-8 encoding) is used to encode all values in the extended header records.The
BINARY
entry indicates that all the values that are recorded in the extended headers for affected files are unencoded binary data from the underlying system. - linkpath
-
The path name of a link that is created to another file, of any type, previously archived. This record overrides the linkname field in the following
ustar
header block(s).The following
ustar
header block determines the type of link that is created, whether hard or symbolic. In the latter case, the linkpath value is the contents of the symbolic link. pax Translates the name of the link (contents of the symbolic link) from the UTF8 encoding to the character set appropriate for the local file system.When used in write or copy mode, pax includes a link path extended header record for each link whose path name cannot be represented entirely with the members of the portable character set other than NULL.
mtime
-
The file modification time of the following file(s), equivalent to the value of the st_mtime member of the stat structure for a file. This record overrides the mtime field in the following header block(s). The modification time is restored if the process has the appropriate privilege to do so.
path
-
The pathname of the following file(s). This record overrides the name and prefix fields in the following header block(s). pax Translates the path name of the file from the UTF8 encoding to the character set appropriate for the local file system. When used in write or copy mode, pax includes a path extended header record for each file whose path name cannot be represented entirely with the members of the portable character set other than NULL.
realtime
.any-
The keywords that are prefixed by real time are reserved for future POSIX real-time standardization. pax Recognizes but silently ignores them.
security
.any-
The keywords that are prefixed by security are reserved for future POSIX security standardization. pax Recognizes but silently ignores them.
size
-
The size of the file is in octets, expressed as a decimal number by using digits from ISO/IEC 646. This record overrides the size field in the following header block(s). When used in write or copy mode, pax includes a size of extended header record for each file with a size value greater than 999,999,999,999.
uid
-
The user ID of the user that owns the file, expressed as a decimal number by using digits from ISO/IEC 646.. This record overrides the uid field in the following header block(s). When used in write or copy mode, pax includes a uid extended header record for each file whose owner ID is greater than 99,999,999.
uname
-
The owner of the following file(s), formatted as a username in the user database. This record overrides the uid and uname fields in the following header block(s), and any uid extended header record. When used in read, copy, or list mode, pax translates the name from the UTF8 encoding in the header record to the character set appropriate for the user database on the receiving system. If any of the UTF8 characters cannot be translated, and if the -o invalid=UTF8 option is not specified, the results are undefined. When used in write or copy mode, pax includes an uname extended header record for each file whose username cannot be represented entirely with the letters and digits of the portable character set.
If the value field is zero length, it deletes 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 ignores the contents of that header block field. Extended header keyword precedence
-
(Applicable only to the -x pax format.)
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 determines a file attribute in this sequence:
- If -o delete=keyword-prefix is used, the affected attribute is determined from step (7) if applicable, or ignored otherwise.
- If -o keyword:=NULL is used, the affected attribute is ignored.
- If -o keyword:=value is used, the affected attribute is assigned the value.
- If value exists in a file-specific extended header record, the affected attribute is assigned the value. When extended header records conflict, the last one given in the header takes precedence.
- If -o keyword=value is used, the affected attribute is assigned the value.
- If a value exists in a global extended header record, the affected attribute is assigned the value. When global extended header records conflict, the last one given in the global header takes precedence.
- Otherwise, the attribute is determined from the
ustar
header block.
Flag Interaction and Processing Order
The flags that operate on the names of files or archive members (-c, -i, -n, -s, -u, and -v) interact as follows:
- When extracting files, archive members are selected according to the user-specified pattern parameters as modified by the -c, -n, and -u flags. Then, any -s, and -i flags modify, in that order, the names of the selected files. The -v flag writes the names resulting from these modifications.
- When writing files to an archive file, or when copying files, the files are selected according to the user-specified pathnames as modified by the -n (this option is not valid for Copy Mode) and -u flags. Then, any -s, and -i flags modify, in that order, the names resulting from these modifications. The -v flag writes the names resulting from the modification.
- If both the -u and -n flags are specified, the pax command does not consider a file that is selected unless it is newer than the file to which it is compared.
List Mode Format Specifications
In list
mode with the -o listopt=format option, the format argument
is applied for each selected file. pax appends a newline character
to the listopt
output for each selected file. The format argument
is used as the format string described in printf()
, with the
following exceptions:
- The sequence keyword can occur before a format conversion specifier. The
conversion argument is defined by the value of keyword. The following keywords
are supported:
- Any of the field name entries for
ustar
andcpio
header blocks. - Any keyword that is defined for the extended header or provided as an extension within the 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 is the value from the applicable header field or extended header, without any trailing NULLs.
All keyword-values used as conversion arguments are translated from the UTF8 encoding to the character set appropriate for the local file system, user database, and so on, as applicable.
- Any of the field name entries for
- An extra conversion character,
T
, specifies time formats. TheT
conversion character can be preceded by the sequence keyword=subformat, where subformat is a date format that is allowed by thedate
command. The default keyword ismtime
and the default subformat is: %b %e %H:%M %Y. - An extra conversion character,
M
, specifies the file mode string as displayed by thels -l
command. If keyword is omitted, themode
keyword is used. For example,%.1M
writes the single character corresponding to the entry type field of thels -l
command. - An extra conversion character,
D
, specifies the device for block or special files, if applicable. If not applicable and keyword is specified, then this conversion is equivalent to %keyword u. If not applicable and keyword is omitted, this conversion is equivalent to<space>
. - An extra conversion character,
F
, specifies a pathname. TheF
conversion character can be preceded by a sequence of comma-separated keywords:keyword,keyword...
The values for all the non-null keywords are concatenated together, each separated by a /. The default is path if the keyword path is defined; otherwise, the default is prefix,name.
- An extra conversion character,
L
, specifies a symbolic link expansion. If the current file is a symbolic link, then %L expands to:"%s -> %s"
, value_of_keyword, contents_of_linkOtherwise, the %L conversion character is equivalent to %F.
Exit Status
This command returns the following exit values:
Item | Description |
---|---|
0 |
Successful completion. |
>0 |
An error occurred. |
Security
- Attention RBAC users
- Attention RBAC users: This command can perform privileged operations. Only privileged users can run privileged operations. For more information about authorizations and privileges, see Privileged Command Database in Security. For a list of privileges and the authorizations that are associated with this command, see the lssecattr command or the getcmdattr subcommand.
Examples
- To copy the
olddir
directory hierarchy tonewdir
, enter:mkdir newdir
pax -rw olddir newdir
- To copy the contents of the current directory to the tape drive,
enter:
pax -wf /dev/rmt0
- To archive the file
xxx
asXXX
and display the successful substitution, enter one of the following commands:pax -wvf/dev/rfd0 -s /xxx/XXX/p xxx
pax -wvf/dev/rfd0 -s/x/X/gp xxx
- To read a file from a standard input and dump it to a datastream
file with a specified size, enter:
dd if=/dev/hd6 bs=36b count=480 | pax -wf /dev/rfd0 -o datastream=_filename_,datastr_size=_size_
- To list the files in an archive pax.ar in
a specified format, enter:
pax -v -o listopt="start %F end" -f pax.ar
- To create an archive pax.ar in pax format,
enter :
pax -wf pax.ar -x pax file1
- To extract a file from an archive pax.ar in pax format
with a new path, enter :
pax -rvf pax.ar -x pax -o path=newfilename
- To copy the contents of a symbolic link from source to destination,
enter:
pax -rwL srclink destdir
- To extract files from the archive with group name as
bin
, enter:pax -rvf pax.ar -x pax -o gname=bin
- To ignore the path name from the archive in pax format
during extraction, enter:
pax -rvf pax.ar -o delete=path
- To avoid the truncation of long user and group names while creating
the archive, enter:
pax -wEf file.pax file
- To copy the
olddir
directory hierarchy tonewdir
with ACL and EA associated with the files, enter:mkdir newdir pax -rUw olddir newdir
Files
Item | Description |
---|---|
/usr/bin/pax | Contains the pax command. |