PAX(1POSIX)
๐ hey bestie, it's PAX time ๐
okay so this is PAX(1POSIX), straight outta the POSIX Programmer's Manual, and it's genuinely one of the most useful little gremlins in the whole toolbox. stay with me, we're gonna get through it together. ๐ซถ
๐ธ PROLOG ๐ธ
so, real talk: this manual page is part of the POSIX Programmer's Manual. If you're on Linux, the implementation of this interface may differ โ like, actually differ โ so go consult the corresponding Linux manual page for the details on Linux behavior. Or, plot twist, the interface might not be implemented on Linux at all. ๐
๐ NAME ๐
pax โ portable archive interchange โจ
like, that's the whole vibe. portable. archive. interchange. iconic.
๐ฆ SYNOPSIS ๐ฆ
okay so there are FOUR whole forms and they all slap differently:
pax [-dv] [-c|-n] [-H|-L] [-o options] [-f archive] [-s replstr]...
[pattern...]
pax -r[-c|-n] [-dikuv] [-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] [-o options]... [-p string]...
[-s replstr]... [file...] directory
๐ DESCRIPTION ๐
so pax is gonna read, write, and write lists of the members of archive files, and also copy whole directory hierarchies. A bunch of archive formats are supported โ check the -x format option for that tea. ๐
The action it takes depends on whether -r and/or -w are hanging around. Those two options give you four modes of operation: list, read, write, and copy mode โ and they line up, in order, with the four forms in the SYNOPSIS. Cute, right?
- list โ this is list mode, aka when neither
-rnor-wis specified.paxwrites the names of the members of the archive file it reads from standard input โ but only the ones whose pathnames match the patterns you gave โ out to standard output. And if a named file is a directory? Then the whole file hierarchy rooted at that file gets listed too. ๐ฆ - read โ read mode, aka when
-ris specified but-wis not.paxextracts the members of the archive file read from standard input, matching the specified patterns. If an extracted file is a directory, the file hierarchy rooted at that file gets extracted as well. The extracted files get created with pathname resolution performed using the directory wherepaxwas invoked as the current working directory.
If you try to extract a directory that already exists, that is not considered an error. If you try to extract a FIFO that already exists, that is also not considered an error. no drama, we move.
The ownership, access times, modification times, and file mode of the restored files? That whole situation is discussed under the -p option. โจ
- write โ write mode, aka when
-wis specified but-ris not.paxwrites the contents of the file operands to standard output in an archive format. If you don't give it any file operands, it reads a list of files to copy from standard input, one per line, and processes each entry like it had been a file operand on the command line. A file of type directory includes all the files in the file hierarchy rooted at that file. ๐ - copy โ copy mode, aka when both
-rand-ware specified.paxcopies the file operands to the destination directory.
If no file operands are specified, a list of files to copy gets read from standard input, one per line. A file of type directory includes all the files in the file hierarchy rooted at the file.
The effect of the copy is as if the copied files were written to a pax format archive file and then subsequently extracted โ except that copying sockets may be supported even if archiving them in write mode is not supported, and 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 POSIX.1โ2017, the results are implementation-defined. Otherwise, it shall be an error for the file named by the directory operand to not exist, to not be writable by the user, or to not be a file of type directory. ๐ค
In read or copy modes, if intermediate directories are necessary to extract an archive member, pax performs actions equivalent to the mkdir() function defined in the System Interfaces volume of POSIX.1โ2017, called with these arguments:
- The intermediate directory used as the path argument
- The value of the bitwise-inclusive OR of
S_IRWXU,S_IRWXG, andS_IRWXOas 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 didn't match, and exits with a non-zero exit status. it will absolutely tell on you. ๐
The archive formats described in the EXTENDED DESCRIPTION section get automatically detected on input. The default output archive format is implementation-defined.
A single archive can span multiple files, bestie. pax determines โ 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 don't store file contents with each name that causes a hard link: if the file containing the data isn't extracted during this pax session, then 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. ๐
And when it's traversing directories, pax detects infinite loops โ like, entering a previously visited directory that's an ancestor of the last file visited. When it detects an infinite loop, it writes a diagnostic message to standard error and terminates. periodt.
๐ OPTIONS ๐
pax conforms to the Base Definitions volume of POSIX.1โ2017, Section 12.2, Utility Syntax Guidelines โ except that the order of presentation of the -o, -p, and -s options is significant. yeah. order matters. don't shuffle them. ๐
The following options shall be supported:
-rโ Read an archive file from standard input. ๐ฅ-wโ Write files to standard output in the specified archive format. ๐ค-aโ Append files to the end of the archive. It is implementation-defined which devices on the system support appending. Additional file formats unspecified by this volume ofPOSIX.1โ2017may impose restrictions on appending. ๐ซ-bblocksize โ Block the output at a positive decimal integer number of bytes per write to the archive file. Devices and archive formats may impose restrictions on blocking. Blocking shall be automatically determined on input. Conforming applications shall not specify a blocksize value larger than32256. Default blocking when creating archives depends on the archive format. (See the-xoption below.)-cโ Match all file or archive members except those specified by the pattern or file operands. (the classic "everything but this" move ๐ )-dโ Cause files of type directory being copied or archived, or archive members of type directory being extracted or listed, to match only the file or archive member itself โ not the file hierarchy rooted at the file. so, shallow. ๐-farchive โ Specify the pathname of the input or output archive, overriding the default standard input (in list or read modes) or standard output (write mode).-Hโ If a symbolic link referencing a file of type directory is specified on the command line,paxshall archive the file hierarchy rooted in the file referenced by the link, using the name of the link as the root of the file hierarchy. Otherwise, if a symbolic link referencing a file of any other file type whichpaxcan normally archive is specified on the command line, thenpaxshall archive the file referenced by the link, using the name of the link. The default behavior, when neither-Hnor-Lare specified, shall be to archive the symbolic link itself. ๐-iโ Interactively rename files or archive members. For each archive member matching a pattern operand, or file matching a file operand, a prompt shall be written to the file/dev/tty. The prompt shall contain the name of the file or archive member, but the format is otherwise unspecified. A line shall then be read from/dev/tty. If this line is blank, the file or archive member shall be skipped. If this line consists of a single period, the file or archive member shall be processed with no modification to its name. Otherwise, its name shall be replaced with the contents of the line.paxshall immediately exit with a non-zero exit status if end-of-file is encountered when reading a response, or if/dev/ttycannot be opened for reading and writing.
โ ๏ธ heads up bestie: the results of extracting a hard link to a file that has been renamed during extraction are unspecified.
-kโ Prevent the overwriting of existing files. ๐-lโ (that's the letter ell, yes really.) In copy mode, hard links shall be made between the source and destination file hierarchies whenever possible. If specified in conjunction with-Hor-L, when a symbolic link is encountered, the hard link created in the destination file hierarchy shall be to the file referenced by the symbolic link. If specified when neither-Hnor-Lis specified, when a symbolic link is encountered, the implementation shall create a hard link to the symbolic link in the source file hierarchy, or copy the symbolic link to the destination. ๐ง
okay and that's where part 1 ends โ more coming, don't go anywhere ๐
-Lโ bestie, this one is about symlinks ๐. If a symbolic link that points at a file of type directory shows up on the command line, or gets encountered while pax is traversing a file hierarchy, pax shall archive the whole file hierarchy rooted in the file the link references โ and it uses the name of the link as the root of that file hierarchy. Otherwise (so: the link points at any other file type pax can normally archive), pax shall archive the file referenced by the link, again using the name of the link. And the default behavior, when neither-Hnor-Lare specified? It shall archive the symbolic link itself. No dereferencing, no drama ๐-nโ select the first archive member that matches each pattern operand, and like, that's it. No more than one archive member shall be matched for each pattern (though members of type directory shall still match the file hierarchy rooted at that file, because of course they do ๐ซถ).-ooptions โ this is the big one, the main character ๐ค. It feeds information to the implementation so it can modify the algorithm for extracting or writing files. The value of options shall consist of one or more<comma>-separated keywords, shaped like this:
keyword[[:]=value][,keyword[[:]=value], ...]
Some keywords apply only to certain file formats โ each description says which. And lowkey important: 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 POSIX.1โ2017, Section 3.282, Portable Filename Character Set.
Note: keywords are not expected to be filenames, bestie โ they just follow the same character composition rules as portable filenames. It's giving "vibes only" โจ
Keywords can be preceded with white space. The value field shall consist of zero or more characters; and 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, and 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. Yeah. Last one wins, the earlier one is just ghosted ๐ป.
The following keyword values of options shall be supported for the file formats as indicated:
delete=pattern ๐๏ธ
(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 Section 2.13.1, Patterns Matching a Single Character and Section 2.13.2, Patterns Matching Multiple Characters. For example:
-o delete=security.*
would suppress security-related information. See pax Extended Header for extended header record keyword usage.
When multiple -odelete=pattern options are specified, the patterns shall be additive; all keywords matching the specified string patterns shall be omitted from extended header records that pax produces. Stack them, bestie ๐ง
exthdr.name=string ๐ท๏ธ
(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:
%dโ the directory name of the file, equivalent to the result of thedirnameutility on the translated pathname.%fโ the filename of the file, equivalent to the result of thebasenameutility on the translated pathname.%pโ the process ID of the pax process.%%โ a%character.
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
globexthdr.name=string ๐
(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:
%nโ an integer that represents the sequence number of the global extended header record in the archive, starting at1.%pโ the process ID of the pax process.%%โ a%character.
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.
invalid=action ๐จ
(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:
- In read or copy mode, a filename or link name that contains character encodings invalid in the destination hierarchy. (For example, the name may contain embedded NULs.)
- In read or copy mode, a filename or link name that is longer than the maximum allowed in the destination hierarchy (for either a pathname component or the entire pathname).
- In list mode, any character string value (filename, link name, user name, and so on) that cannot be written in the codeset and current locale of the implementation.
The following mutually-exclusive values of the action argument are supported:
binaryโ In write mode, pax shall generate ahdrcharset=BINARYextended header record for each file with a filename, link name, group name, owner name, or any other field in an extended header record that cannot be translated to the UTFโ8 codeset, allowing the archive to contain the files with unencoded extended header record values. In read or copy mode, pax shall use the values specified in the header without translation, regardless of whether this may overwrite an existing file with a valid name. In list mode, pax shall behave identically to thebypassaction.
okay so for invalid=option, you've got these modes, and they are iconic in their own chaotic way:
bypassโ in read or copy mode,paxshall bypass the file, causing no change to the destination hierarchy. In list mode,paxshall write all requested valid values for the file, but its method for writing invalid values is unspecified. โจrenameโ in read or copy mode,paxshall act as if the-ioption 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,paxshall behave identically to thebypassaction. ๐UTFโ8โ 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,paxshall use the actual UTFโ8 encoding for the name. If ahdrcharsetextended header record is in effect for this file, the character set specified by that record shall be used instead of UTFโ8. If ahdrcharset=BINARYextended header record is in effect for this file, no translation shall be performed. ๐ฆwriteโ in read or copy mode,paxshall write the file, translating the name, regardless of whether this may overwrite an existing file with a valid name. In list mode,paxshall behave identically to thebypassaction. ๐
If no -o invalid=option is specified, pax shall act as if -oinvalid=bypass were specified. Any overwriting of existing files that may be allowed by the -oinvalid= actions shall be subject to permission (-p) and modification time (-u) restrictions, and shall be suppressed if the -k option is also specified.
bestie, note the no-space -oinvalid=bypass โ copy it exactly, don't go adding a space, okay? ๐ญ
linkdataโ (applicable only to the-x paxformat.) In write mode,paxshall 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. ๐ฅlistopt=formatโ this keyword specifies the output format of the table of contents produced when the-voption is specified in list mode. See List Mode Format Specifications. To avoid ambiguity, thelistopt=formatshall be the only or finalkeyword=valuepair in a-ooption-argument; all characters in the remainder of the option-argument shall be considered part of the format string. When multiple-olistopt=formatoptions are specified, the format strings shall be considered a single, concatenated string, evaluated in command line order. โญtimesโ (applicable only to the-x paxformat.) When used in write or copy mode,paxshall includeatimeandmtimeextended 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:
keyword=valueโ when used in write or copy mode, these keyword/value pairs shall be included at the beginning of the archive as typeflaggglobal 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 typeflaggglobal extended header records. ๐keyword:=valueโ when used in write or copy mode, these keyword/value pairs shall be included as records at the beginning of a typeflagxextended header for each file. (This shall be equivalent to the<equals-sign>form except that it creates no typeflaggglobal 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. If the -o delete=pattern, -o keyword=value, or -o keyword:=value options are used to override or remove any extended header data needed to find files in an archive (e.g., -o delete=size for a file whose size cannot be represented in a ustar header or -o size=100 for a file whose size is not 100 bytes), the behavior is undefined.
okay so that last bit? undefined behavior โ do not pass go, do not collect $200, just don't. ๐
-p stringโ specify one or more file characteristic options (privileges). Thestringoption-argument shall be a string specifying file characteristics to be retained or discarded on extraction. The string shall consist of the specification charactersa,e,m,o, andp. Other implementation-defined characters can be included. Multiple characteristics can be concatenated within the same string and multiple-poptions can be specified. The meaning of the specification characters are as follows:aโ do not preserve file access times. ๐งeโ preserve the user ID, group ID, file mode bits (see the Base Definitions volume of POSIX.1โ2017, Section 3.169, File Mode Bits), access time, modification time, and any other implementation-defined file characteristics. โจmโ do not preserve file modification times. ๐ฐ๏ธoโ preserve the user ID and group ID. ๐ซถpโ 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 Section 1.1.1.4, 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.
bestie the way-p emeworks is last one wins โ somwins and modification times get preserved. periodt. ๐
-s replstrโ modify file or archive member names named bypatternor file operands according to the substitution expressionreplstr, using the syntax of theedutility. The concepts ofaddressandlineare meaningless in the context of thepaxutility, and shall not be supplied. The format shall be:
-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) back-references, or subexpression matching. The old string shall also be permitted to contain <newline> characters. ๐ฆ
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. ๐ธ
-tโ when reading files from the file system, and if the user has the permissions required byutime()to do so, set the access time of each file read to the access time that it had before being read bypax. โฐ-uโ ignore files that are older than a pre-existing file or archive member with the same name (older = less recent file modification time, bestie, we're comparing mtimes). How this plays out depends on your mode, so let's go:- read mode: an archive member with the same name as a file in the file system gets extracted if the archive member is newer than the file.
- write mode: an archive file member with the same name as a file in the file system gets superseded if the file is newer than the archive member. If
-ais also specified, this is accomplished by appending to the archive; otherwise it's unspecified whether it's accomplished by actual replacement in the archive or by appending to the archive. (Yeah. Unspecified. We don't know. ๐) - copy mode: the file in the destination hierarchy gets 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.
-vโ in list mode, produce a verbose table of contents (peep the STDOUT section for that). Otherwise, write archive member pathnames to standard error (peep STDERR). โจ-xformat โ specify the output archive format, bestie. Thepaxutility shall support these formats:cpioโ the cpio interchange format; see the EXTENDED DESCRIPTION section. The default blocksize for this format for character special archive files shall be5120. Implementations shall support all blocksize values less than or equal to32256that are multiples of512.paxโ the pax interchange format; see the EXTENDED DESCRIPTION section. The default blocksize for this format for character special archive files shall be5120. Implementations shall support all blocksize values less than or equal to32256that are multiples of512.ustarโ the tar interchange format; see the EXTENDED DESCRIPTION section. The default blocksize for this format for character special archive files shall be10240. Implementations shall support all blocksize values less than or equal to32256that are multiples of512.
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. No cap. It's giving hard stop.
-Xโ when traversing the file hierarchy specified by a pathname,paxshall not descend into directories that have a different device ID (st_dev; see the System Interfaces volume of POSIX.1โ2017,stat()). So it stays on one device, periodt.
Specifying more than one of the mutually-exclusive options -H and -L shall not be considered an error, bestie โ and the last option specified shall determine the behavior of the utility. Last one wins, that's the vibe. ๐
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-uoptions. Then, any-sand-ioptions shall modify, in that order, the names of the selected files. The-voption 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
-nand-uoptions. Then, any-sand-ioptions shall modify, in that order, the names of these selected files. The-voption 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. Fr fr, it's gotta be newer or it's not coming. ๐ซถ
๐ List Mode Format Specifications ๐
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 POSIX.1โ2017, Chapter 5, File Format Notation โ with the exceptions 1. through 6. defined in the EXTENDED DESCRIPTION section of printf, plus these following exceptions, bestie:
- The sequence
(keyword)can occur before a format conversion specifier. The conversion argument is defined by the value of keyword. The implementation shall support the following keywords:- Any of the Field Name entries in Table 4-14, ustar Header Block and Table 4-16, Octet-Oriented cpio Archive Entry. The implementation may support the cpio keywords without the leading
c_in addition to the form required by Table 4-16, Octet-Oriented cpio Archive Entry. - 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.
- Any of the Field Name entries in Table 4-14, ustar Header Block and Table 4-16, Octet-Oriented cpio Archive Entry. The implementation may support the cpio keywords without the leading
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 (or alternative encoding specified by any hdrcharset extended header record) to the character set appropriate for the local file system, user database, and so on, as applicable.
- An additional conversion specifier character,
T, shall be used to specify time formats. TheTconversion specifier character can be preceded by the sequence(keyword=subformat), where subformat is a date format as defined bydateoperands. The default keyword shall bemtimeand the default subformat shall be:
%b %e %H:%M %Y
- An additional conversion specifier character,
M, shall be used to specify the file mode string as defined inlsStandard Output. If(keyword)is omitted, themodekeyword shall be used. For example,%.1Mwrites the single character corresponding to the<entry type>field of thels -lcommand. ๐ - An additional conversion specifier character,
D, shall be used to specify the device for block or special files, if applicable, in an implementation-defined format. If not applicable, and(keyword)is specified, then this conversion shall be equivalent to%(keyword)u. If not applicable, and(keyword)is omitted, then this conversion shall be equivalent to<space>. - An additional conversion specifier character,
F, shall be used to specify a pathname. TheFconversion character can be preceded by a sequence of<comma>-separated keywords:
(keyword[,keyword] ... )
The values for all the *keyword*s 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).
- An additional conversion specifier character,
L, shall be used to specify a symbolic link expansion. If the current file is a symbolic link, then%Lshall expand to:
"%s -> %s", <value of keyword>, <contents of link>
Otherwise, the %L conversion specification shall be the equivalent of %F.
๐ OPERANDS ๐
The following operands shall be supported, bestie:
- directory โ the destination directory pathname for copy mode. ๐
- file โ a pathname of a file to be copied or archived.
- pattern โ a pattern matching one or more pathnames of archive members. A pattern must be given in the name-generating notation of the pattern matching notation in Section 2.13, Pattern Matching Notation, including the filename expansion rules in Section 2.13.3, Patterns Used for Filename Expansion. The default, if no pattern is specified, is to select all members in the archive. The whole thing. Every last one. ๐ฆ
๐ STDIN ๐
- In write mode, the standard input shall be used only if no file operands are specified. It shall be a file containing a list of pathnames, each terminated by a
<newline>character. - In list and read modes, if
-fis not specified, the standard input shall be an archive file. - Otherwise, the standard input shall not be used. Not even a little. ๐
๐ธ INPUT FILES ๐ธ
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. So yeah, it's talking straight to your terminal, iykyk. ๐
๐ธ ENVIRONMENT VARIABLES ๐ธ
okay so these are the env vars that get a say in how pax runs, bestie โ set them, don't set them, that's your business:
LANGโ gives a default value for any of the internationalization variables that are unset or null. (The deets live in the Base Definitions volume of POSIX.1-2017, Section 8.2, Internationalization Variables โ that's where the precedence rules for figuring out locale category values are spelled out.)LC_ALLโ if you set this to a non-empty string, it straight up overrides every other internationalization variable. main character behavior tbh ๐LC_COLLATEโ sets the locale for the behavior of ranges, equivalence classes, and multi-character collating elements in: the pattern matching expressions for the pattern operand, the basic regular expression for the-soption, and the extended regular expression defined for theyesexprlocale keyword over in theLC_MESSAGEScategory.LC_CTYPEโ sets the locale for interpreting sequences of bytes of text data as characters (single-byte vs multi-byte characters in arguments and input files, for example), for the behavior of character classes used in the extended regular expression defined for theyesexprlocale keyword inLC_MESSAGES, and for pattern matching.LC_MESSAGESโ sets the locale used to process affirmative responses, and the locale used to affect the format and contents of diagnostic messages and prompts written to standard error.LC_TIMEโ sets the format and contents of date and time strings when the-voption is specified.NLSPATHโ sets the location of message catalogs for the processing ofLC_MESSAGES.TMPDIRโ sets the pathname that provides part of the default global extended header record file, as described for the-o globexthdr=keyword in the OPTIONS section.TZโ sets the timezone used to calculate date and time strings when the-voption is specified. IfTZis unset or null, an unspecified default timezone shall be used. yes, unspecified. no cap. ๐ญ
โก ASYNCHRONOUS EVENTS โก
Default. that's the whole section. slay ๐
๐ STDOUT ๐
In write mode, if -f isn't specified, the standard output is 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 -olistopt=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 -olistopt=format option, the table of contents of the selected archive members shall be written to standard output using this 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. (mystery fields. iconic. ๐)
In list mode, standard output shall not be buffered more than a pathname (plus any associated information and a <newline> terminator) at a time.
๐ฆ STDERR ๐ฆ
If -v is specified in read, write, or copy modes, pax shall write the pathnames it processes to the standard error output using this 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.
okay listen up for this one: when using the-xpaxarchive format, if a filename, link name, group name, owner name, or any other field in an extended header record cannot be translated between the codeset in use for that extended header record and the character set of the current locale,paxshall write a diagnostic message to standard error, shall process the file as described for the-o invalid=option, and then shall continue processing with the next file. so it yells, does the invalid-value thing, and keeps it moving. we love resilience. ๐ช
๐ OUTPUT FILES ๐
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 (-oinvalid=) tests allow it. all three have to say yes, no exceptions. ๐ซถ
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.
๐ EXTENDED DESCRIPTION ๐
โจ pax Interchange Format โจ
A pax archive tape or file produced in the -xpax 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:
- An optional header block with extended header records. This header block is of the form described in pax Header Block, with a
typeflagvalue ofxorg. The extended header records, described in pax Extended Header, shall be included as the data for this header block. - A header block that describes the file. Any fields in the preceding optional extended header shall override the associated fields in this header block for this file.
- Zero or more blocks that contain the contents of the file.
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 Figure 4-1, 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.
Figure 4-1: pax Format Archive Example
๐ pax Header Block ๐
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:
xโ represents extended header records for the following file in the archive (which shall have its own ustar header block). The format of these extended header records shall be as described in pax Extended Header.gโ represents global extended header records for the following files in the archive. The format of these extended header records shall be as described in pax Extended Header. Each value shall affect all subsequent files that do not override that value in their own extended header record, and it keeps affecting them until another global extended header record is reached that provides another value for the same field. Thetypeflaggglobal headers should not be used with interchange media that could suffer partial data loss in transporting the archive.
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 โ plot twist โ 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. So 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. ๐
๐ซถ pax Extended Header ๐ซถ
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 encoding. The <length> field, <blank>, <equals-sign>, and <newline> shown shall be limited to the portable character set, as encoded in UTF-8. The <keyword> 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>. If there is a hdrcharset extended header in effect for a file, the value field for any gname, linkpath, path, and uname extended header records shall be encoded using the character set specified by the hdrcharset extended header record; otherwise, the value field shall be encoded using UTF-8. The value field for all other keywords specified by POSIX.1-2008 shall be encoded using UTF-8.
Okay so real talk, the <keyword> field has to be one of the entries from this list, or a keyword that your implementation decided to add as an extension. โจ And there are rules, bestie:
- Keywords made up entirely of lowercase letters, digits, and periods? Those are reserved for future standardization โ do not touch, not yours. ๐ โโ๏ธ
- A keyword shall not include an
<equals-sign>.
Also, quick notation note so you're not confused later: when you see file(s) or block(s) in this list, that's just acknowledging that a keyword affects the following single file after a typeflag x extended header โ but possibly multiple files after typeflag g. ๐
And one more thing: any requirements in this 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 -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. Cute, right? ๐
atime
The file access time for the following file(s) โ equivalent to the value of the st_atime member of the stat structure for a file, as described by the stat() function. The access time shall be restored if the process has appropriate privileges required to do so. The format of the <value> shall be as described in pax Extended Header File Times.
charset
The name of the character set used to encode the data in the following file(s). The entries in this list are defined to refer to known standards; additional names may be agreed on between the originator and recipient. ๐ซถ
ISO-IR 646 1990โISO/IEC 646:1990ISO-IR 8859 1 1998โISO/IEC 8859โ1:1998ISO-IR 8859 2 1999โISO/IEC 8859โ2:1999ISO-IR 8859 3 1999โISO/IEC 8859โ3:1999ISO-IR 8859 4 1998โISO/IEC 8859โ4:1998ISO-IR 8859 5 1999โISO/IEC 8859โ5:1999ISO-IR 8859 6 1999โISO/IEC 8859โ6:1999ISO-IR 8859 7 1987โISO/IEC 8859โ7:1987ISO-IR 8859 8 1999โISO/IEC 8859โ8:1999ISO-IR 8859 9 1999โISO/IEC 8859โ9:1999ISO-IR 8859 10 1998โISO/IEC 8859โ10:1998ISO-IR 8859 13 1998โISO/IEC 8859โ13:1998ISO-IR 8859 14 1998โISO/IEC 8859โ14:1998ISO-IR 8859 15 1999โISO/IEC 8859โ15:1999ISO-IR 10646 2000โISO/IEC 10646:2000ISO-IR 10646 2000 UTF-8โISO/IEC 10646, UTF-8 encodingBINARYโNone.
The encoding is included in an extended header for information only. When pax is used as described in POSIX.1โ2008, 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, whether pax includes a charset extended header record for a file is implementation-defined.
comment
A series of characters used as a comment. All characters in the <value> field shall be ignored by pax. Simple as that. ๐ค
gid
The group ID of the group that owns the file, expressed as a decimal number using digits from the ISO/IEC 646:1991 standard. This record shall override the gid field in the following header block(s). When used in write or copy mode, pax shall include a gid extended header record for each file whose group ID is greater than 2097151 (octal 7777777). ๐
gname
The group of the file(s), formatted as a group name in the group database. This record shall override the gid and gname fields in the following header block(s), and any gid extended header record. When used in read, copy, or list mode, pax shall translate the name from the encoding in the header record to the character set appropriate for the group database on the receiving system. If any of the characters cannot be translated, and if neither the -oinvalid=UTFโ8 option nor the -oinvalid=binary option is specified, the results are implementation-defined. ๐ญ
When used in write or copy mode, pax shall include 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 used to encode the value field of the gname, linkpath, path, and uname pax extended header records. The entries in this list are defined to refer to known standards; additional names may be agreed between the originator and the recipient. ๐ฆ
ISO-IR 10646 2000 UTF-8โISO/IEC 10646, UTF-8 encodingBINARYโNone.
If no hdrcharset extended header record is specified, the default character set used to encode all values in extended header records shall be the ISO/IEC 10646โ1:2000 standard UTFโ8 encoding. ๐
The BINARY entry indicates that all values recorded in extended headers for affected files are unencoded binary data from the underlying system.
linkpath
The pathname of a link being created to another file, of any type, previously archived. This record shall override the linkname field in the following ustar header block(s). The following ustar header block shall determine the type of link created:
- If
typeflagof the following header block is1, it shall be a hard link. ๐ - If
typeflagis2, it shall be a symbolic link, and thelinkpathvalue shall be the contents of the symbolic link.
The pax utility shall translate the name of the link (contents of the symbolic link) from the encoding in the header to the character set appropriate for the local file system. When used in write or copy mode, pax shall include a linkpath extended header record for each link whose pathname cannot be represented entirely with the members of the portable character set other than NUL.
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, as described in the stat() function. This record shall override the mtime field in the following header block(s). The modification time shall be restored if the process has appropriate privileges required to do so. The format of the <value> shall be as described in pax Extended Header File Times. โฐ
path
The pathname of the following file(s). This record shall override the name and prefix fields in the following header block(s). The pax utility shall translate the pathname of the file from the encoding in the header to the character set appropriate for the local file system. ๐ธ
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.
realtime.any
The keywords prefixed by realtime. are reserved for future standardization. Not yours yet, bestie. ๐
security.any
The keywords prefixed by security. are reserved for future standardization. Same energy. ๐
size
The size of the file in octets, expressed as a decimal number using digits from the ISO/IEC 646:1991 standard. This record shall override the size field in the following header block(s). When used in write or copy mode, pax shall include a size extended header record for each file with a size value greater than 8589934591 (octal 77777777777). ๐
uid
The user ID of the file owner, expressed as a decimal number using digits from the ISO/IEC 646:1991 standard. This record shall override the uid field in the following header block(s). When used in write or copy mode, pax shall include a uid extended header record for each file whose owner ID is greater than 2097151 (octal 7777777). ๐
uname
The owner of the following file(s), formatted as a user name in the user database. This record shall override 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 shall translate the name from the encoding in the header record to the character set appropriate for the user database on the receiving system. If any of the characters cannot be translated, and if neither the -oinvalid=UTFโ8 option nor the -oinvalid=binary option is specified, the results are implementation-defined. ๐ญ
When used in write or copy mode, pax shall include a uname extended header record for each file whose user name cannot be represented entirely with the letters and digits of the portable character set. โจ
okay so if that <value> field is literally zero length?? ๐ bestie that's a delete button. It shall delete any header block field, any previously entered extended header value, or any global extended header value that has the same name. Gone. Poof. ๐ซถ
And if a keyword in an extended header record (or inside a -o option-argument, same energy) overrides or deletes a corresponding field in the ustar header block, then pax shall ignore the contents of that header block field. Like, it's not even invited to the group chat anymore. ๐
Unlike the ustar header block fields, NULs shall not delimit <value>s. Nope! All characters within the <value> field shall be considered data for the field. And none of the length limitations of the ustar header block fields in Table 4-14, ustar Header Block shall apply to the extended header records. Extended headers said "no rules, only vibes." โจ
๐ pax Extended Header Keyword Precedence ๐
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:
- If
-odelete=keyword-prefixis used, the affected attributes shall be determined from step 7., if applicable, or ignored otherwise. - If
-okeyword:=is used, the affected attributes shall be ignored. - If
-okeyword:=valueis used, the affected attribute shall be assigned the value. - If there is a
typeflagxextended header record, the affected attribute shall be assigned the<value>. When extended header records conflict, the last one given in the header shall take precedence. - If
-okeyword=valueis used, the affected attribute shall be assigned the value. - If there is a
typeflaggglobal extended header record, the affected attribute shall be assigned the<value>. When global extended header records conflict, the last one given in the global header shall take precedence. - Otherwise, the attribute shall be determined from the ustar header block.
bestie the order MATTERS, this is a whole ranking system and step 7 is the "well, guess we're doing it the old way" fallback ๐
๐ pax Extended Header File Times ๐
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. Nested tenths. Tenth-ception. ๐ง
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. Minimal digits, maximum precision, that's the vibe. โจ
๐ฆ ustar Interchange Format ๐ฆ
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. That's the little "we're done here" bow on top. ๐
The logical records may be grouped for physical I/O operations, as described under the -bblocksize 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.
๐ Table 4-14: ustar Header Block ๐
nameโ octet offset0, length100octetsmodeโ octet offset100, length8octetsuidโ octet offset108, length8octetsgidโ octet offset116, length8octetssizeโ octet offset124, length12octetsmtimeโ octet offset136, length12octetschksumโ octet offset148, length8octetstypeflagโ octet offset156, length1octetlinknameโ octet offset157, length100octetsmagicโ octet offset257, length6octetsversionโ octet offset263, length2octetsunameโ octet offset265, length32octetsgnameโ octet offset297, length32octetsdevmajorโ octet offset329, length8octetsdevminorโ octet offset337, length8octetsprefixโ octet offset345, length155octets
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 POSIX.1โ2008. 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. At least it tells you it's ghosting you. Communication queen. ๐
Each field within the header logical record is contiguous; that is, there is no padding used. Each character on the archive medium shall be stored contiguously. Snug. Cozy. No gaps. ๐ซถ
The fields magic, uname, and gname are character strings each terminated by a NUL character. The fields name, linkname, and prefix are NUL-terminated character strings except when all characters in the array contain non-NUL characters including the last character. The version field is two octets containing the characters "00" (zero-zero). The typeflag contains a single character. All other fields are leading zero-filled octal numbers using digits from the ISO/IEC 646:1991 standard IRV. Each numeric field is terminated by one or more <space> or NUL characters.
The name and the prefix fields shall produce the pathname of the file. A new pathname shall be formed, if prefix is not an empty string (its first character is not NUL), by concatenating prefix (up to the first NUL character), a <slash> character, and name; otherwise, name is used alone. In either case, name is terminated at the first NUL character. If prefix begins with a NUL character, it shall be ignored. In this manner, pathnames of at most 256 characters can be supported. If a pathname does not fit in the space provided, pax shall notify the user of the error, and shall not store any part of the fileโheader or dataโon the medium. ๐ญ
The linkname field, described below, shall not use the prefix to produce a pathname. As such, a linkname is limited to 100 characters. If the name does not fit in the space provided, pax shall notify the user of the error, and shall not attempt to store the link on the medium.
The mode field provides 12 bits encoded in the ISO/IEC 646:1991 standard octal digit representation. The encoded bits shall represent the following values:
๐ Table: ustar mode Field ๐
- Bit value
04000, POSIX.1โ2008 bitS_ISUIDโ Set UID on execution. - Bit value
02000, POSIX.1โ2008 bitS_ISGIDโ Set GID on execution. - Bit value
01000, POSIX.1โ2008 bit<reserved>โ Reserved for future standardization. - Bit value
00400, POSIX.1โ2008 bitS_IRUSRโ Read permission for file owner class. - Bit value
00200, POSIX.1โ2008 bitS_IWUSRโ Write permission for file owner class. - Bit value
00100, POSIX.1โ2008 bitS_IXUSRโ Execute/search permission for file owner class. - Bit value
00040, POSIX.1โ2008 bitS_IRGRPโ Read permission for file group class. - Bit value
00020, POSIX.1โ2008 bitS_IWGRPโ Write permission for file group class. - Bit value
00010, POSIX.1โ2008 bitS_IXGRPโ Execute/search permission for file group class. - Bit value
00004, POSIX.1โ2008 bitS_IROTHโ Read permission for file other class. - Bit value
00002, POSIX.1โ2008 bitS_IWOTHโ Write permission for file other class. - Bit value
00001, POSIX.1โ2008 bitS_IXOTHโ Execute/search permission for file other class.
okay so when you need appropriate privileges to set one of those mode bits, and the person restoring files from the archive does not have them? Those specific mode bits get ignored. Periodt. Also โ some of the mode bits in the archive format are not mentioned anywhere else in this volume of POSIX.1โ2017, so if your implementation doesn't support those bits, it may just ignore them. No drama. ๐
The uid and gid fields are the user and group ID of the owner and group of the file, respectively. Obviously. ๐
โจ the fields, one by one โจ
size โ it's the size of the file in octets, bestie. But listen: if the typeflag field says the file is type 1 (a link) or type 2 (a symbolic link), then size shall be specified as zero. If typeflag says type 5 (directory), then size gets interpreted as described under the definition of that record type. And no data logical records are stored for types 1, 2, or 5. none. zero. nada.
If typeflag is 3 (character special file), 4 (block special file), or 6 (FIFO), the meaning of size is unspecified by this volume of POSIX.1โ2017, and no data logical records shall be stored on the medium. Extra note for type 6: size shall be ignored when reading. ๐
If typeflag is set to any other value, then the number of logical records written following the header shall be:
(size+511)/512
...ignoring any fraction in the result of the division. Math girlies stay winning. ๐งฎโจ
mtime โ this shall be the modification time of the file at the time it was archived. It's the ISO/IEC 646:1991 standard representation of the octal value of the modification time obtained from the stat() function. That's it, that's the field. ๐
chksum โ this one shall be the ISO/IEC 646:1991 standard IRV representation of the octal value of the simple sum of all octets in the header logical record. Each octet in the header shall be treated as an unsigned value. These values shall be added to an unsigned integer, initialized to zero, the precision of which is not less than 17 bits. And here's the sneaky bit: when calculating the checksum, the chksum field is treated as if it were all <space> characters. ๐คซ
๐ typeflag ๐
The typeflag field specifies the type of file archived. Now โ if a particular implementation doesn't recognize the type, or the user doesn't have appropriate privileges to create that type, the file shall be extracted as if it were a regular file if the file type is defined to have a meaning for the size field that could cause data logical records to be written on the medium (see the previous description for size). And if conversion to a regular file occurs, pax shall produce an error indicating that the conversion took place. iykyk. โ ๏ธ
All of the typeflag fields shall be coded in the ISO/IEC 646:1991 standard IRV:
0โ Represents a regular file. For backwards-compatibility, atypeflagvalue of binary zero ('\0') should be recognized as meaning a regular file when extracting files from the archive. Archives written with this version of the archive file format create regular files with atypeflagvalue of the ISO/IEC 646:1991 standard IRV'0'.1โ Represents a file linked to another file, of any type, previously archived. Such files are identified by having the same device and file serial numbers, and pathnames that refer to different directory entries. All such files shall be archived as linked files. The linked-to name is specified in thelinknamefield with a NUL-character terminator if it is less than 100 octets in length.2โ Represents a symbolic link. The contents of the symbolic link shall be stored in thelinknamefield.3,4โ Represent character special files and block special files respectively. In this case thedevmajoranddevminorfields shall contain information defining the device, the format of which is unspecified by this volume of POSIX.1โ2017. Implementations may map the device specifications to their own local specification or may ignore the entry.5โ Specifies a directory or subdirectory. On systems where disk allocation is performed on a directory basis, thesizefield shall contain the maximum number of octets (which may be rounded to the nearest disk block allocation unit) that the directory may hold. Asizefield of zero indicates no such limiting. Systems that do not support limiting in this manner should ignore thesizefield.6โ Specifies a FIFO special file. Note that the archiving of a FIFO file archives the existence of this file and not its contents. ๐ซ7โ Reserved to represent a file to which an implementation has associated some high-performance attribute. Implementations without such extensions should treat this file as a regular file (type0).A-Zโ The letters'A'to'Z', inclusive, are reserved for custom implementations. All other values are reserved for future versions of this standard. ๐
It is unspecified whether files with pathnames that refer to the same directory entry are archived as linked files or as separate files. And if they are archived as linked files, that means attempting to extract both pathnames from the resulting archive will always cause an error (unless the -u option is used) because the link cannot be created. F in the chat. ๐ญ
It is also unspecified whether files with the same device and file serial numbers being appended to an archive are treated as linked files to members that were in the archive before the append. Mystery behavior, lowkey iconic. ๐ฆ
Attempts to archive a socket shall produce a diagnostic message when ustar interchange format is used, but may be allowed when pax interchange format is used. Handling of other file types is implementation-defined. ๐
magic โ the field that says this archive was output in this archive format. If this field contains ustar (the five characters from the ISO/IEC 646:1991 standard IRV shown followed by NUL), the uname and gname fields shall contain the ISO/IEC 646:1991 standard IRV representation of the owner and group of the file, respectively (truncated to fit, if necessary). โจ
And when the file is restored by a privileged, protection-preserving version of the utility, the user and group databases shall be scanned for these names. If found, the user and group IDs contained within these files shall be used rather than the values contained within the uid and gid fields. Names > numbers, I guess. ๐
๐ cpio Interchange Format ๐
The octet-oriented cpio archive format shall be a series of entries, each comprising a header that describes the file, the name of the file, and then the contents of the file. Three-part baddie. ๐ซถ
An archive may be recorded as a series of fixed-size blocks of octets. This blocking shall be used only to make physical I/O more efficient. The last group of blocks shall always be at the full size. No half-blocks, bestie. โญ
For the octet-oriented cpio archive format, the individual entry information shall be in the order indicated and described by the following table; see also the <cpio.h> header.
Table 4-16: Octet-Oriented cpio Archive Entry ๐ง
Header fields โ Header Field Name / Length (in Octets) / Interpreted as:
c_magicโ 6 โ Octal numberc_devโ 6 โ Octal numberc_inoโ 6 โ Octal numberc_modeโ 6 โ Octal numberc_uidโ 6 โ Octal numberc_gidโ 6 โ Octal numberc_nlinkโ 6 โ Octal numberc_rdevโ 6 โ Octal numberc_mtimeโ 11 โ Octal numberc_namesizeโ 6 โ Octal numberc_filesizeโ 11 โ Octal number
Filename field โ Filename Field Name / Length / Interpreted as:
c_nameโc_namesizeโ Pathname string
File data field โ File Data Field Name / Length / Interpreted as:
c_filedataโc_filesizeโ Data
๐ cpio Header ๐
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:
c_magicโ Identify the archive as being a transportable archive by containing the identifying value"070707". โจc_dev,c_inoโ Contains values that uniquely identify the file within the archive (that is, no files contain the same pair ofc_devandc_inovalues unless they are links to the same file). The values shall be determined in an unspecified manner.c_modeโ Contains the file type and access permissions as defined in the following table.
Table 4-17: Values for cpio c_mode Field
File Permissions Name โจ Value โจ Indicates:
C_IRUSRโ000400โ read by ownerC_IWUSRโ000200โ write by ownerC_IXUSRโ000100โ execute by ownerC_IRGRPโ000040โ read by groupC_IWGRPโ000020โ write by groupC_IXGRPโ000010โ execute by groupC_IROTHโ000004โ read by othersC_IWOTHโ000002โ write by othersC_IXOTHโ000001โ execute by othersC_ISUIDโ004000โ set uidC_ISGIDโ002000โ set gidC_ISVTXโ001000โ reserved
File Type Name โจ Value โจ Indicates:
C_ISDIRโ040000โ directoryC_ISFIFOโ010000โ FIFOC_ISREGโ0100000โ regular fileC_ISLNKโ0120000โ symbolic linkC_ISBLKโ060000โ block special fileC_ISCHRโ020000โ character special fileC_ISSOCKโ0140000โ socketC_ISCTGโ0110000โ reserved
Directories, FIFOs, symbolic links, and regular files shall be supported on a system that conforms to this volume of POSIX.1โ2017, bestie โ that's the baseline. Any additional values that were defined before are reserved so they stay compatible with systems that already exist. Extra file types? Sure, they may be supported โ but please don't write those into archives you plan to ship to other systems, because they're not gonna know what to do with them. ๐
c_uid โ holds the user ID of the owner. ๐
c_gid โ holds the group ID of the group.
c_nlink โ holds a number greater than or equal to the number of links in the archive that reference the file. Now here's the tea โ: if you're using the -a option to append to a cpio archive, then pax does not have to account for the files in the already-existing part of the archive when it's calculating c_nlink values for the appended part. And it also doesn't have to touch the c_nlink values in the existing part, even if you're appending extra files that share the same c_dev and c_ino values. Not its problem, not its job. ๐
c_rdev โ holds implementation-defined info for character or block special files.
c_mtime โ holds the latest time the file was modified, as of the moment the archive was created. ๐ฐ๏ธ
c_namesize โ holds the length of the pathname, including the terminating NUL character. Yes, the NUL counts. It always counts. ๐ญ
c_filesize โ holds the length, in octets, of the data section that comes after the header structure.
๐๏ธ cpio Filename ๐๏ธ
The c_name field shall contain the pathname of the file. How long is this field, in octets? Literally just the value of c_namesize. Simple math, no cap. โจ
If a filename shows up on the medium that would create an invalid pathname, it's implementation-defined whether the data from that file gets stored on the file hierarchy, and under what name it gets stored.
Every character shall be represented in the ISO/IEC 646:1991 standard IRV. And for maximum portability between implementations, you should pick names from characters represented by the portable filename character set, as octets with the most significant bit zero. ๐ If an implementation does support characters outside the portable filename character set in names for files, users, and groups, then one or more implementation-defined encodings of those characters shall be provided for interchange purposes.
But โ and this is important, bestie โ pax shall never create filenames on the local system that can't be accessed via the procedures described earlier in this volume of POSIX.1โ2017. Never ever. ๐ซ If a filename is found on the medium that would create an invalid filename, it's implementation-defined whether the data from the file gets stored on the local file system, and under what name it gets stored. pax may choose to ignore these files โ but only as long as it produces an error saying it's ignoring the file. Like, it can ghost them, but it has to announce that it's ghosting them. ๐ซถ
๐ง cpio File Data ๐ง
Right after c_name, there shall be c_filesize octets of data. How you interpret that data depends on the file itself:
- For regular files, the data shall consist of the contents of the file.
- For symbolic links, the data shall consist of the contents of the symbolic link.
- If
c_filesizeis zero, then there's no data inc_filedata.
When you're restoring from an archive:
- If the user doesn't have appropriate privileges to create a file of the specified type,
paxshall ignore the entry and write an error message to standard error. Sorry bestie, permissions are permissions. ๐ - Only regular files and symbolic links have data to be restored. Assuming a regular file meets any selection criteria the user might have imposed on the format-reading utility, that data shall be restored.
- If a user doesn't have appropriate privileges to set a particular mode flag, that flag shall be ignored. And heads up: some of the mode flags in the archive format aren't mentioned anywhere else in this volume of POSIX.1โ2017. If the implementation doesn't support those flags, they may be ignored. It's giving "we don't know her". ๐
๐ cpio Special Entries ๐
FIFO special files, directories, and the trailer shall be recorded with c_filesize equal to zero. Symbolic links shall be recorded with c_filesize equal to the length of the contents of the symbolic link. For other special files, c_filesize is unspecified by this volume of POSIX.1โ2017.
The header for the next file entry in the archive shall be written directly after the last octet of the file entry that came before it. And a header denoting the filename TRAILER!!! shall indicate the end of the archive โ that's the finish line, periodt. ๐ The contents of the octets in the last block of the archive, after that header, are undefined. Don't look at them. Don't count on them. They're not for you. ๐
โจ EXIT STATUS โจ
Here's what pax hands back when it's done:
0โ all files were processed successfully. Slay. ๐>0โ an error occurred. ๐ญ
๐ CONSEQUENCES OF ERRORS ๐
Okay so if pax can't create a file or a link while reading an archive, or can't find a file while writing an archive, or can't preserve the user ID, group ID, or file mode when the -p option is specified โ here's the deal: a diagnostic message shall be written to standard error, and a non-zero exit status shall be returned. But processing shall continue. It does not stop. It keeps going. Main character energy. ๐ฅ
And in the specific case where pax can't create a link to a file, pax shall not, by default, create a second copy of that file. Just so we're clear.
If the extraction of a file from an archive gets prematurely terminated by a signal or an error,paxmay have only partially extracted that file โ or, if the-noption was not specified, it may have extracted a file with the same name as the one the user specified, but which is not the file the user actually wanted. ๐จ Big yikes. On top of that, the file modes of extracted directories may have additional bits from theS_IRWXUmask set, plus incorrect modification and access times. It's giving chaos. ๐
The following sections are informative.
๐ APPLICATION USAGE ๐
Okay bestie, this is the "we love you, but please be careful" section. Standards-people said it with their whole chest, and honestly? They're right. ๐ซถ
Heads up about -a: caution is advised when you use the -a option to append to a cpio format archive. Here's the tea โ if any of the files you're appending happen to get the same c_dev and c_ino values as a file that's already in the existing part of the archive, then on extraction they might get treated as links to that file. So it's risky to use -a with cpio format, except when:
- you're doing it on the same system the original archive was created on,
- with the same
paxutility, - and you know there's been little or no file system activity since the original archive was created that could lead to any of the files being appended getting the same
c_devandc_inovalues as an unrelated file in the existing part of the archive.
Also, when you're (intentionally!) appending additional links to a file in the existing part of the archive, the c_nlink values in the modified archive can end up smaller than the number of links to the file in the archive โ which may mean the links are not preserved on extraction. ๐
The -p (privileges) option was invented to reconcile differences between historical tar and cpio implementations. In particular, the two utilities use -m in diametrically opposed ways. The -p option also provides a consistent means of extending the ways in which future file attributes can be addressed โ like for enhanced security systems or high-performance files. It looks complex, but honestly there are really only two modes that get used the most:
-p eโ "Preserve everything". This is what the historical superuser โ someone with all appropriate privileges โ would use, to preserve all aspects of the files as they are recorded in the archive. Theeflag is the sum ofoandp, and other implementation-defined attributes.-p pโ "Preserve" the file mode bits. This is what a user with regular privileges would use when they wanted to preserve aspects of the file other than the ownership. The file times are preserved by default, but two other flags are offered to disable these and use the time of extraction instead.
The one-pathname-per-line format of standard input precludes pathnames containing <newline> characters. Like, no. ๐ญ And yeah, such pathnames violate the portable filename guidelines, but they may exist anyway, and their presence may inhibit usage of pax within shell scripts. This problem is inherited from historical archive programs. The fix? Just list your filename arguments on the command line instead of on standard input. Periodt. โจ
It is almost certain that appropriate privileges are required for pax to accomplish parts of this volume of POSIX.1-2017. Specifically:
- creating files of type block special or character special,
- restoring file access times unless the files are owned by the user (the
-toption), - or preserving file owner, group, and mode (the
-poption)
โฆall probably require appropriate privileges. ๐
In read mode, implementations are permitted to overwrite files when the archive has multiple members with the same name. Ngl, this may fail if the permissions on the first version of the file do not permit it to be overwritten.
Also, the cpio and ustar formats can only support files up to 8589934592 bytes (8 โ 2^30) in size. That's the ceiling, bestie. ๐ง
When archives containing binary header information are listed, the filenames printed may cause strange behavior on some terminals. Not a vibe, just a fact.
Okay so here's a whole little scenario. When all of the following are true:
- A file of type directory is being placed into an archive.
- The
ustararchive format is being used. - The pathname of the directory is less than or equal to
155bytes long (it will fit in theprefixfield in theustarheader block). - The last component of the pathname of the directory is longer than
100bytes long (it will not fit in thenamefield in theustarheader block).
โฆthen some implementations of the pax utility will place the entire directory pathname in the prefix field, set the name field to an empty string, and place the directory in the archive. Other implementations of the pax utility will give an error under these conditions because the name field is not large enough to hold the last component of the directory name.
This standard allows either behavior. ๐ฏ However โ and this is the important part โ when extracting a directory from a ustar format archive, this standard requires that all implementations be able to extract a directory even if the name field contains an empty string, as long as the prefix field does not also contain an empty string. Write that down. ๐
โจ EXAMPLES โจ
The following command:
pax -w -f /dev/rmt/1m .
copies the contents of the current directory to tape drive 1, medium density (assuming historical System V device naming procedures โ the historical BSD device name would be /dev/rmt9). ๐พ
The following commands:
mkdir newdir
pax -rw olddir newdir
copy the olddir directory hierarchy to newdir.
pax -r -s ',^//*usr//*,,' -f a.pax
reads the archive a.pax, with all files rooted in /usr in the archive extracted relative to the current directory.
Using the option:
-o listopt="%M %(atime)T %(size)D %(name)s"
overrides the default output description in Standard Output and instead writes:
-rw-rw--- Jan 12 15:53 2003 1492 /usr/foo/bar
Using the options:
-o listopt='%L\t%(size)D\n%.7' \
-o listopt='(name)s\n%(atime)T\n%T'
overrides the default output description in Standard Output and instead writes:
/usr/foo/bar -> /tmp 1492
/usr/fo
Jan 12 15:53 1991
Jan 31 15:53 2003
Look at that formatting slay. ๐
๐ธ RATIONALE ๐ธ
The pax utility was new for the ISO POSIX-2:1993 standard. It represents a peaceful compromise between advocates of the historical tar and cpio utilities. ๐๏ธ
A fundamental difference between cpio and tar was in the way directories were treated. The cpio utility did not treat directories differently from other files, and to select a directory and its contents required that each file in the hierarchy be explicitly specified. For tar, a directory matched every file in the file hierarchy it rooted.
The pax utility offers both interfaces; by default, directories map into the file hierarchy they root. The -d option causes pax to skip any file not explicitly referenced, as cpio historically did. The tar-style behavior was chosen as the default because it was believed that this was the more common usage, and because tar is the more commonly available interface, as it was historically provided on both System V and BSD implementations.
The data interchange format specification in this volume of POSIX.1-2017 requires that processes with appropriate privileges'' shall **always** restore the ownership and permissions of extracted files exactly as archived. If viewed from the historic equivalence between superuser and appropriate privileges'', there are two problems with this requirement. First, users running as superusers may unknowingly set dangerous permissions on extracted files. Second, it is needlessly limiting, in that superusers cannot extract files and own them as superuser unless the archive was created by the superuser. (It should be noted that restoration of ownerships and permissions for the superuser, by default, is historical practice in cpio, but not in tar.)
In order to avoid these two problems, the pax specification has an additional ``privilege'' mechanism: the -p option. Only a pax invocation with the privileges needed, and which has the -p option set using the e specification character, has appropriate privileges to restore full ownership and permission information. ๐
Note also that this volume of POSIX.1-2017 requires that the file ownership and access permissions shall be set, on extraction, in the same fashion as the creat() function when provided with the mode stored in the archive. This means that the file creation mask of the user is applied to the file permissions.
Users should note that directories may be created by pax while extracting files with permissions that are different from those that existed at the time the archive was created. When extracting sensitive information into a directory hierarchy that no longer exists, users are encouraged to set their file creation mask appropriately to protect these files during extraction. Protect the files, bestie. ๐ก๏ธ
The table of contents output is written to standard output to facilitate pipeline processing. Iconic behavior honestly.
An early proposal had hard links displaying for all pathnames. This was removed because it complicates the output of the case where -v is not specified and does not match historical cpio usage. The hard-link information is available in the -v display.
The description of the -l option allows implementations to make hard links to symbolic links. Earlier versions of this standard did not specify any way to create a hard link to a symbolic link, but many implementations provided this capability as an extension. If there are hard links to symbolic links when an archive is created, the implementation is required to archive the hard link in the archive (unless -H or -L is specified). When in read mode and in copy mode, implementations supporting hard links to symbolic links should use them when appropriate.
The archive formats inherited from the POSIX.1-1990 standard have certain restrictions that have been brought along from historical usage. For example, there are restrictions on the length of pathnames stored in the archive. When pax is used in copy(-rw) mode (copying directory hierarchies), the ability to use extensions from the -xpax format overcomes these restrictions. โจ
The default blocksize value of 5120 bytes for cpio was selected because it is one of the standard block-size values for cpio, set when the -B option is specified. (The other default block-size value for cpio is 512 bytes, and this was considered to be too small.) The default block value of 10240 bytes for tar was selected because that is the standard block-size value for BSD tar. The maximum block size of 32256 bytes (215-512 bytes) is the largest multiple of 512 bytes that fits into a signed 16-bit tape controller transfer register. There are known limitations in some historical systems that would prevent larger blocks from being accepted.
Historical values were chosen to improve compatibility with historical scripts using dd or similar utilities to manipulate archives. Also, default block sizes for any file type other than character special file has been deleted from this volume of POSIX.1-2017 as unimportant and not likely to affect the structure of the resulting archive. ๐
Okay so, implementations are permitted to modify the block-size value based on the archive format or the device to which the archive is being written. This is to give implementations the opportunity to take advantage of special types of devices, and it should not be used without a great deal of consideration, because it almost certainly decreases archive portability. ๐
The intended use of the -n option was to permit extraction of one or more files from the archive without processing the entire archive. This was viewed by the standard developers as offering significant performance advantages over historical implementations. The -n option in early proposals had three effects:
- It caused special characters in patterns to not be treated specially.
- It caused only the first file that matched a pattern to be extracted.
- It caused
paxto write a diagnostic message to standard error when no file was found matching a specified pattern.
Only the second behavior is retained by this volume of POSIX.1โ2017, for many reasons. First, it is in general not acceptable for a single option to have multiple effects. Second, the ability to make pattern matching characters act as normal characters is useful for parts of pax other than file extraction. Third, a finer degree of control over the special characters is useful because users may wish to normalize only a single special character in a single filename. Fourth, given a more general escape mechanism, the previous behavior of the -n option can be easily obtained using the -s option or a sed script. Finally, writing a diagnostic message when a pattern specified by the user is unmatched by any file is useful behavior in all cases. โจ
In this version, the -n was removed from the copy mode synopsis of pax; it is inapplicable because there are no pattern operands specified in this mode. ๐ซถ
There is another method than pax for copying subtrees in POSIX.1โ2008 described as part of the cp utility. Both methods are historical practice: cp provides a simpler, more intuitive interface, while pax offers a finer granularity of control. Each provides additional functionality to the other; in particular, pax maintains the hard-link structure of the hierarchy while cp does not. It is the intention of the standard developers that the results be similar (using appropriate option combinations in both utilities). The results are not required to be identical; there seemed insufficient gain to applications to balance the difficulty of implementations having to guarantee that the results would be exactly identical. ๐
A single archive may span more than one file. It is suggested that implementations provide informative messages to the user on standard error whenever the archive file is changed. ๐
The -d option (do not create intermediate directories not listed in the archive) found in early proposals was originally provided as a complement to the historic -d option of cpio. It has been deleted. ๐
The -s option in early proposals specified a subset of the substitution command from the ed utility. As there was no reason for only a subset to be supported, the -s option is now compatible with the current ed specification. Since the delimiter can be any non-null character, the following usage with single <space> characters is valid:
pax -s " foo bar " ...
The -t description is worded so as to note that this may cause the access time update caused by some other activity (which occurs while the file is being read) to be overwritten. ๐ฆ
The default behavior of pax with regard to file modification times is the same as historical implementations of tar. It is not the historical behavior of cpio. ๐ธ
Because the -i option uses /dev/tty, utilities without a controlling terminal are not able to use this option. ๐ญ
The -y option, found in early proposals, has been deleted because a line containing a single <period> for the -i option has equivalent functionality. The special lines for the -i option (a single <period> and the empty line) are historical practice in cpio. ๐
In early drafts, a -echarmap option was included to increase portability of files between systems using different coded character sets. This option was omitted because it was apparent that consensus could not be formed for it. In this version, the use of UTFโ8 should be an adequate substitute. โจ
The ISO POSIXโ2:1993 standard and ISO POSIXโ1 standard requirements for pax, however, made it very difficult to create a single archive containing files created using extended characters provided by different locales. This version adds the hdrcharset keyword to make it possible to archive files in these cases without dropping files due to translation errors. ๐ง
Translating filenames and other attributes from a locale's encoding to UTFโ8 and then back again can lose information, as the resulting filename might not be byte-for-byte equivalent to the original. To avoid this problem, users can specify the -o hdrcharset=binary option, which will cause the resulting archive to use binary format for all names and attributes. Such archives are not portable among hosts that use different native encodings (e.g., EBCDIC versus ASCII-based encodings), but they will allow interchange among the vast majority of POSIX file systems in practical use. Also, the -o hdrcharset=binary option will cause pax in copy mode to behave more like other standard utilities such as cp. ๐
If the values specified by the -o exthdr.name=value, -o globexthdr.name=value, or by $TMPDIR (if -o globexthdr.name is not specified) require a character encoding other than that described in the ISO/IEC 646:1991 standard, a path extended header record will have to be created for the file. If a hdrcharset extended header record is active for such headers, it will determine the codeset used for the value field in these extended path header records. These path extended header records always need to be created when writing an archive even if hdrcharset=binary has been specified and would contain the same (binary) data that appears in the ustar header record prefix and name fields. (In other words, an extended header path record is always required to be generated if the prefix or name fields contain non-ASCII characters even when hdrcharset=binary is also in effect for that file.) ๐
The -k option was added to address international concerns about the dangers involved in the character set transformations of -e (if the target character set were different from the source, the filenames might be transformed into names matching existing files) and also was made more general to protect files transferred between file systems with different {NAME_MAX} values (truncating a filename on a smaller system might also inadvertently overwrite existing files). As stated, it prevents any overwriting, even if the target file is older than the source. This version adds more granularity of options to solve this problem by introducing the -oinvalid=optionโspecifically the UTFโ8 and binary actions. (Note that an existing file is still subject to overwriting in this case. The -k option closes that loophole.) ๐ฅ
Some of the file characteristics referenced in this volume of POSIX.1โ2017 might not be supported by some archive formats. For example, neither the tar nor cpio formats contain the file access time. For this reason, the e specification character has been provided, intended to cause all file characteristics specified in the archive to be retained. ๐
It is required that extracted directories, by default, have their access and modification times and permissions set to the values specified in the archive. This has obvious problems in that the directories are almost certainly modified after being extracted and that directory permissions may not permit file creation. One possible solution is to create directories with the mode specified in the archive, as modified by the umask of the user, with sufficient permissions to allow file creation. After all files have been extracted, pax would then reset the access and modification times and permissions as necessary. ๐
The list-mode formatting description borrows heavily from the one defined by the printf utility. However, since there is no separate operand list to get conversion arguments, the format was extended to allow specifying the name of the conversion argument as part of the conversion specification. โญ
The T conversion specifier allows time fields to be displayed in any of the date formats. Unlike the ls utility, pax does not adjust the format when the date is less than six months in the past. This makes parsing the output more predictable. ๐
The D conversion specifier handles the ability to display the major/minor or file size, as with ls, by using %-8(size)D. ๐
The L conversion specifier handles the ls display for symbolic links. ๐
Conversion specifiers were added to generate existing known types used for ls. โจ
๐ฆ pax Interchange Format ๐ฆ
The new POSIX data interchange format was developed primarily to satisfy international concerns that the ustar and cpio formats did not provide for file, user, and group names encoded in characters outside a subset of the ISO/IEC 646:1991 standard. The standard developers realized that this new POSIX data interchange format should be very extensible because there were other requirements they foresaw in the near future:
- Support international character encodings and locale information ๐
- Support security information (ACLs, and so on) ๐
- Support future file types, such as realtime or contiguous files โฑ๏ธ
- Include data areas for implementation use ๐งฐ
- Support systems with words larger than 32 bits and timers with subsecond granularity โก
The following were not goals for this format because these are better handled by separate utilities or are inappropriate for a portable format:
- Encryption ๐
- Compression ๐๏ธ
- Data translation between locales and codesets ๐
inodestorage ๐พ
The format chosen to support the goals is an extension of the ustar format. Of the two formats previously available, only the ustar format was selected for extensions because:
- It was easier to extend in an upwards-compatible way. It offered version flags and header block type fields with room for future standardization. The
cpioformat, while possessing a more flexible file naming methodology, could not be extended without breaking some theoretical implementation or using a dummy filename that could be a legitimate filename. ๐ ๏ธ - Industry experience since the original โtar warsโ fought in developing the
ISO POSIXโ1standard has clearly been in favor of theustarformat, which is generally the default output format selected forpaximplementations on new systems. ๐
Okay so the new format had one more tiny goal in mind, bestie: being reasonable when an older tar or pax utility happened to read an archive. ๐ Like, the vibe check was real. Because the POSIX.1โ1990 standard mandated that a โformat-reading utilityโ had to treat unrecognized typeflag values as regular files, this allowed the format to include all the extended information in a pseudo-regular file that preceded each real file. An option is given that lets the archive creator set up reasonable names for these files on the older systems. Also, the normative text suggests that reasonable file access values be used for this ustar header block. Making these header files inaccessible for convenient reading and deleting would not be reasonable. File permissions of 600 or 700 are suggested. ๐
ngl, the ustar typeflag field was used to accommodate the additional functionality of the new format rather than magic or version because the POSIX.1โ1990 standard (and, by reference, the previous version of pax) mandated the behavior of the format-reading utility when it encountered an unknown typeflag, but was silent about the other two fields. ๐ซข
Early proposals for the first version of this standard contained a proposed archive format that was based on compatibility with the standard for tape files (ISO 1001, similar to the format used historically on many mainframes and minicomputers). This format was overly complex, fr fr, and required considerable overhead in volume and header records. Furthermore, the standard developers felt that it would not be acceptable to the community of POSIX developers, so it was later changed to be a format more closely related to historical practice on POSIX systems. ๐
The prefix and name split of pathnames in ustar was replaced by the single path extended header record for simplicity. โจ
The concept of a global extended header (typeflagg) was controversial, periodt. If this were applied to an archive being recorded on magnetic tape, a few unreadable blocks at the beginning of the tape could be a serious problem; a utility attempting to extract as many files as possible from a damaged archive could lose a large percentage of file header information in this case. ๐ญ However, if the archive were on a reliable medium, such as a CDโROM, the global extended header offers considerable potential size reductions by eliminating redundant information. Thus, the text warns against using the global method for unreliable media and provides a method for implanting global information in the extended header for each file, rather than in the typeflag g records. ๐
No facility for data translation or filtering on a per-file basis is included because the standard developers could not invent an interface that would allow this in an efficient manner. If a filter, such as encryption or compression, is to be applied to all the files, it is more efficient to apply the filter to the entire archive as a single file. The standard developers considered interfaces that would invoke a shell script for each file going into or out of the archive, but the system overhead in this approach was considered to be too high. ๐
One such approach would be to have filter= records that give a pathname for an executable. When the program is invoked, the file and archive would be open for standard input/output and all the header fields would be available as environment variables or command-line arguments. The standard developers did discuss such schemes, but they were omitted from POSIX.1โ2008 due to concerns about excessive overhead. Also, the program itself would need to be in the archive if it were to be used portably. ๐ง
There is currently no portable means of identifying the character set(s) used for a file in the file system. Therefore, pax has not been given a mechanism to generate charset records automatically. The only portable means of doing this is for the user to write the archive using the -ocharset=string command line option. This assumes that all of the files in the archive use the same encoding. The โimplementation-definedโ text is included to allow for a system that can identify the encodings used for each of its files. ๐ธ
The table of standards that accompanies the charset record description is acknowledged to be very limited, no cap. Only a limited number of character set standards is reasonable for maximal interchange. Any character set is, of course, possible by prior agreement. It was suggested that EBCDIC be listed, but it was omitted because it is not defined by a formal standard. Formal standards, and then only those with reasonably large followings, can be included here, simply as a matter of practicality. The <value>s represent names of officially registered character sets in the format required by the ISO 2375:1985 standard. ๐
The normal <comma> or <blank>-separated list rules are not followed in the case of keyword options to allow ease of argument parsing for getopts. ๐
Further information on character encodings is in pax Archive Character Set Encoding/Decoding. ๐ฆ
The standard developers have reserved keyword name space for vendor extensions, iykyk. It is suggested that the format to be used is:
VENDOR.keyword
where VENDOR is the name of the vendor or organization in all uppercase letters. It is further suggested that the keyword following the <period> be named differently than any of the standard keywords so that it could be used for future standardization, if appropriate, by omitting the VENDOR prefix. ๐
The <length> field in the extended header record was included to make it simpler to step through the records, even if a record contains an unknown format (to a particular pax) with complex interactions of special characters. It also provides a minor integrity checkpoint within the records to aid a program attempting to recover files from a damaged archive. ๐
There are no extended header versions of the devmajor and devminor fields because the unspecified format ustar header field should be sufficient. If they are not, vendor-specific extended keywords (such as VENDOR.devmajor) should be used. ๐ ๏ธ
Device and i-number labeling of files was not adopted from cpio; files are interchanged strictly on a symbolic name basis, as in ustar. ๐
Just as with the ustar format descriptions, the new format makes no special arrangements for multi-volume archives. Each of the pax archive types is assumed to be inside a single POSIX file and splitting that file over multiple volumes (diskettes, tape cartridges, and so on), processing their labels, and mounting each in the proper sequence are considered to be implementation details that cannot be described portably. ๐ฆ
The pax format is intended for interchange, not only for backup on a single (family of) systems. It is not as densely packed as might be possible for backup, and thatโs the tea:
- It contains information as coded characters that could be coded in binary.
- It identifies extended records with name fields that could be omitted in favor of a fixed-field layout.
- It translates names into a portable character set and identifies locale-related information, both of which are probably unnecessary for backup.
The requirements on restoring from an archive are slightly different from the historical wording, allowing for non-monolithic privilege to bring forward as much as possible. In particular, attributes such as โhigh performance fileโ might be broadly but not universally granted while set-user-ID or chown() might be much more restricted. There is no implication in POSIX.1โ2008 that the security information be honored after it is restored to the file hierarchy, in spite of what might be improperly inferred by the silence on that topic. That is a topic for another standard. ๐
Links are recorded in the fashion described here because a link can be to any file type. It is desirable in general to be able to restore part of an archive selectively and restore all of those files completely. If the data is not associated with each link, it is not possible to do this. However, the data associated with a file can be large, and when selective restoration is not needed, this can be a significant burden. The archive is structured so that files that have no associated data can always be restored by the name of any link name of any link, and the user may choose whether data is recorded with each instance of a file that contains data. The format permits mixing of both types of links in a single archive; this can be done for special needs, and pax is expected to interpret such archives on input properly, despite the fact that there is no pax option that would force this mixed case on output. (When -o linkdata is used, the output must contain the duplicate data, but the implementation is free to include it or omit it when -o linkdata is not used.) ๐
The time values are included as extended header records for those implementations needing more than the eleven octal digits allowed by the ustar format. Portable file timestamps cannot be negative. If pax encounters a file with a negative timestamp in copy or write mode, it can reject the file, substitute a non-negative timestamp, or generate a non-portable timestamp with a leading '-'. Even though some implementations can support finer file-time granularities than seconds, the normative text requires support only for seconds since the Epoch because the ISO POSIXโ1 standard states them that way. The ustar format includes only mtime; the new format adds atime and ctime for symmetry. The atime access time restored to the file system will be affected by the -p a and -p e options. The ctime creation time (actually inode modification time) is described with appropriate privileges so that it can be ignored when writing to the file system. POSIX does not provide a portable means to change file creation time. Nothing is intended to prevent a non-portable implementation of pax from restoring the value. โฐ
The gid, size, and uid extended header records were included to allow expansion beyond the sizes specified in the regular tar header. New file system architectures are emerging that will exhaust the 12-digit size field. There are probably not many systems requiring more than 8 digits for user and group IDs, but the extended header values were included for completeness, allowing overrides for all of the decimal values in the tar header. ๐ข
The standard developers intended to describe the effective results of pax with regard to file ownerships and permissions; implementations are not restricted in timing or sequencing the restoration of such, provided the results are as specified. periodt. โ
Much of the text describing the extended headers is lowkey talking about how they get used in "write or copy modes". The copy mode references are there because of the normative text, which says, and I quote: "The effect of the copy shall be as if the copied files were written to an archive file and then subsequently extracted ...". Like, there is literally no way to test whether pax is actually generating the extended headers in copy mode, bestie โ but the effects have to be as if it had. Periodt. ๐
โจ pax Archive Character Set Encoding/Decoding โจ ๐ฆ
Okay so picture this: you gotta exchange archives of files between systems that have different native codesets. ๐ Filenames, group names, and user names have to be preserved to the fullest extent possible when an archive gets read on the receiving platform. And translating the contents of files? Not it โ that is not within the scope of the pax utility, bestie.
There's also gonna be the need to represent characters that just do not exist on the receiving platform. And here's the tea: these unsupported characters cannot be automatically folded to the local set of characters, because of the chance of collisions. ๐ That could literally result in overwriting previous extracted files from the archive, or pre-existing files on the system. Not the vibe.
So for these reasons, the codeset used to represent characters inside the extended header records of the pax archive has to be sufficiently rich to handle all commonly used character sets. The fields that require translation include, at a minimum:
- filenames
- user names
- group names
- link pathnames
Implementations may also wish to have localized extended keywords that use non-portable characters. Fancy. ๐
The standard developers considered the following options:
- The archive creator specifies the well-defined name of the source codeset. The receiver must then recognize the codeset name and perform the appropriate translations to the destination codeset.
- The archive creator includes within the archive the character mapping table for the source codeset used to encode extended header records. The receiver must then read the character mapping table and perform the appropriate translations to the destination codeset.
- The archive creator translates the extended header records in the source codeset into a canonical form. The receiver must then perform the appropriate translations to the destination codeset.
Now the approach that incorporates the name of the source codeset? It poses the problem of codeset name registration, and it makes the archive useless to pax archive decoders that don't recognize that codeset. Oop. ๐
And because parts of an archive may be corrupted, the standard developers felt that including the character map of the source codeset was too fragile. Like, losing this one key component could result in making the entire archive useless. (The difference between this and the global extended header decision was that the latter has a workaround โ duplicating extended header records on unreliable media โ but this would be way too burdensome for large character set maps.) ๐ญ
Both of those approaches also put an undue burden on the pax archive receiver, forcing it to handle the cross-product of all source and destination codesets. Exhausting.
So to simplify the translation from the source codeset to the canonical form and from the canonical form to the destination codeset, the standard developers decided that the internal representation should be a stateless encoding. A stateless encoding is one where each codepoint has the same meaning, without regard to the decoder being in a specific state. Example of a stateful encoding? The Japanese Shift-JIS. Example of a stateless encoding? The ISO/IEC 646:1991 standard (equivalent to 7-bit ASCII). Slay. โจ
For these reasons, the standard developers decided to adopt a canonical format for the representation of file information strings. The obvious, well-endorsed candidate is the ISO/IEC 10646โ1:2000 standard (based in part on Unicode), which can be used to represent the characters of virtually all standardized character sets. The standard developers initially agreed upon using UCS2 (16-bit Unicode) as the internal representation. This repertoire of characters provides a sufficiently rich set to represent all commonly-used codesets. ๐
However โ plot twist โ the standard developers found that the 16-bit Unicode representation had some problems. It forced the issue of standardizing byte ordering. And the 2-byte length of each character made the extended header records twice as long for the case of strings coded entirely from historical 7-bit ASCII. So for these reasons, the standard developers chose the UTFโ8 defined in the ISO/IEC 10646โ1:2000 standard. This multi-byte representation encodes UCS2 or UCS4 characters reliably and deterministically, eliminating the need for a canonical byte ordering. Plus, NUL octets and other characters possibly confusing to POSIX file systems do not appear, except to represent themselves. It was realized that certain national codesets take up more space after the encoding, due to their placement within the UCS range; but it was felt that the usefulness of the encoding of the names outweighs the disadvantage of size increase for file, user, and group names. Balance. ๐ง
The encoding of UTFโ8 is as follows:
UCS4 Hex Encoding UTF-8 Binary Encoding
00000000-0000007F 0xxxxxxx
00000080-000007FF 110xxxxx 10xxxxxx
00000800-0000FFFF 1110xxxx 10xxxxxx 10xxxxxx
00010000-001FFFFF 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
00200000-03FFFFFF 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
04000000-7FFFFFFF 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
where each 'x' represents a bit value from the character being translated. ๐
๐ ustar Interchange Format ๐
The description of the ustar format reflects numerous enhancements over pre-1988 versions of the historical tar utility. And the goal of these changes wasn't only to provide the functional enhancements people wanted โ it was also to retain compatibility between new and old versions. And bestie, this compatibility has been retained. Archives written using the old archive format are compatible with the new format. Legacy rights. ๐ซถ
Implementors should be aware that the previous file format did not include a mechanism to archive directory type files. So for this reason, the convention of using a filename ending with <slash> was adopted to specify a directory on the archive. Cute workaround honestly.
The total size of the name and prefix fields have been set to meet the minimum requirements for {PATH_MAX}. If a pathname will fit within the name field, it is recommended that the pathname be stored there without the use of the prefix field. Although the name field is known to be too small to contain {PATH_MAX} characters, the value was not changed in this version of the archive file format โ to retain backwards-compatibility โ and instead the prefix was introduced. Also, because of the earlier version of the format, there is no way to remove the restriction on the linkname field being limited in size to just that of the name field. Trapped by history, lowkey. ๐ญ
The size field is required to be meaningful in all implementation extensions, although it could be zero. This is required so that the data blocks can always be properly counted. Numbers stay numbers. ๐ฅ
It is suggested that if device special files need to be represented that cannot be represented in the standard format, that one of the extension types (AโZ) be used, and that the additional information for the special file be represented as data and be reflected in the size field.
Attempting to restore a special file type, where it is converted to ordinary data and conflicts with an existing filename, need not be specially detected by the utility. If run as an ordinary user, pax should not be able to overwrite the entries in, for example, /dev in any case (whether the file is converted to another type or not). If run as a privileged user, it should be able to do so, and it would be considered a bug if it did not. The same is true of ordinary data files and similarly named special files; it is impossible to anticipate the needs of the user (who could really intend to overwrite the file), so the behavior should be predictable (and thus regular) and rely on the protection system as required. No cap. ๐
The value 7 in the typeflag field is intended to define how contiguous files can be stored in a ustar archive. POSIX.1โ2008 does not require the contiguous file extension, but it does define a standard way of archiving such files so that all conforming systems can interpret these file types in a meaningful and consistent manner. On a system that does not support extended file types, the pax utility should do the best it can with the file and go on to the next. Main character energy: keep it moving. ๐
The file protection modes are those conventionally used by the ls utility. This is extended beyond the usage in the ISO POSIXโ2 standard to support the shared text''</pink> or <pink>sticky'' bit. It is intended that the conformance document should not document anything beyond the existence of and support of such a mode. Further extensions are expected to these bits, particularly with overloading the set-user-ID and set-group-ID flags. The future is coming for these bits fr fr.
๐ cpio Interchange Format ๐
The reference to appropriate privileges in the cpio format refers to an error on standard output; the ustar format does not make comparable statements. Different format, different rules, iykyk.
The model for this format was the historical System V cpio-c data interchange format. This model documents the portable version of the cpio format and not the binary version. It has the flexibility to transfer data of any type described within POSIX.1โ2008, yet is extensible to transfer data types specific to extensions beyond POSIX.1โ2008 (for example, contiguous files). And because it describes existing practice, there is no question of maintaining upwards-compatibility. It's giving "it already works, we just wrote it down." โจ
๐ cpio Header ๐
There has been some concern that the size of the c_ino field of the header is too small to handle those systems that have very large inode numbers. However! The c_ino field in the header is used strictly as a hard-link resolution mechanism for archives. It is not necessarily the same value as the inode number of the file in the location from which that file is extracted. So breathe. ๐ฆ
The name c_magic is based on historical usage. Vibes-based naming, iconic honestly.
๐ cpio Filename ๐
For most historical implementations of the cpio utility, {PATH_MAX} octets can be used to describe the pathname without the addition of any other header fields (the NUL character would be included in this count). {PATH_MAX} is the minimum value for pathname size, documented as 256 bytes. However, an implementation may use c_namesize to determine the exact length of the pathname. With the current description of the <cpio.h> header, this pathname size can be as large as a number that is described in six octal digits. Six! Octal! Digits! Numbers stay numbers. ๐ฅ
Two values are documented under the c_mode field values to provide for extensibility for known file types:
0110 000 โ Reserved for contiguous files. The implementation may treat the rest of the information for this archive like a regular file. If this file type is undefined, the implementation may create the file as a regular file.
Okay so this whole thing is about making the cpio format extensible while still letting you read old archives. Files of an unknown type may be read as โregular filesโ on some implementations. And on a system that does not support extended file types, the pax utility should just do the best it can with the file and go on to the next. fr fr, it's giving resilience ๐
๐ฎ FUTURE DIRECTIONS ๐ฎ
None. That's it. Nothing. Nada. Periodt. ๐
๐ SEE ALSO ๐
- Chapter 2, Shell Command Language,
cp,ed,getopts,ls,printf - The Base Definitions volume of POSIX.1โ2017, Section 3.169, File Mode Bits, Chapter 5, File Format Notation, Chapter 8, Environment Variables, Section 12.2, Utility Syntax Guidelines,
<cpio.h>,<tar.h> - The System Interfaces volume of POSIX.1โ2017,
chown(),creat(),fstatat(),mkdir(),mkfifo(),utime(),write()
Like, go read those if you wanna be a true Unix bestie. iykyk โจ
๐ COPYRIGHT ๐
Okay so some of this text is reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
Not me reading legal text for funโฆ but also, protect the source, bestie. ๐ซถ
This page was brought to you by IEEE/The Open Group, 2017, PAX(1POSIX). Stay iconic, stay POSIX-compliant. ๐โจ
๐ฆ where this page comes from
- debian bookworm: manpages-posix 2017a-2 ยท Other
- debian trixie: manpages-posix 2017a-2 ยท Other
- ubuntu jammy: manpages-posix 2017a-2 ยท Other
- ubuntu noble: manpages-posix 2017a-2 ยท Other
- ubuntu resolute: manpages-posix 2017a-2build1 ยท Other
- ubuntu stonking: manpages-posix 2017a-2.1 ยท Other
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms