LinuxCommandLibrary

pax

Archive and extract files

TLDR

List the contents of an archive

$ pax -f [archive.tar]
copy

List the contents of a gzip archive
$ pax -zf [archive.tar.gz]
copy

Create an archive from files
$ pax -wf [target.tar] [path/to/file1 path/to/file2 ...]
copy

Create an archive from files, using output redirection
$ pax -w [path/to/file1 path/to/file2 ...] > [target.tar]
copy

Extract an archive into the current directory
$ pax -rf [source.tar]
copy

Copy to a directory, while keeping the original metadata; target/ must exist
$ pax -rw [path/to/file1] [path/to/directory1 path/to/directory2 ...] [target/]
copy

SYNOPSIS

pax [-options] [file...]
pax -r [-options] [pattern...]
pax -w [-options] [file...]
pax -rw [-options] [file...] directory

PARAMETERS

-r
    Read from the archive (extract or list mode). If no file operands are given, it extracts all files; otherwise, it extracts files matching the specified patterns.

-w
    Write to the archive (archive mode). If no file operands are given, pax reads from standard input; otherwise, it archives the specified files.

-rw
    Copy files to a destination directory. This mode copies the file hierarchy from the source file(s) to the specified directory, effectively acting like an enhanced cp.

-a
    Append to the archive. This option can only be used with -w mode and requires a seekable archive (e.g., a regular file).

-d
    Create intermediate directories as needed during extraction or copying.

-f archive
    Specify the path to the archive file. If omitted, pax uses standard input (for reading) or standard output (for writing).

-i
    Interactively rename files. For each file, pax prompts the user for a new name or to skip the file. Useful for selective extraction or when managing name conflicts.

-k
    Do not overwrite existing files. When extracting or copying, if a file with the same name already exists, it is not overwritten.

-p string
    Preserve specified file attributes during extraction or copying. Common characters in string include: e (everything: mode, access time, modification time, owner, group, extended attributes), m (modification time), o (owner and group), a (access time).

-s replstr
    Modify file or archive member names using a substitution expression similar to sed. Example: -s '/old/new/'.

-v
    Verbose output. List files being processed by name, useful for monitoring progress and debugging.

-x format
    Specify the archive format to use when writing. Common values include cpio (old cpio format), ustar (old tar format), and pax (the POSIX.1-2001 format, also known as POSIX tar).

-X
    Do not cross device boundaries. When archiving or copying, pax will not descend into directories on different file systems.

DESCRIPTION

pax (Portable Archive eXchange) is a powerful and versatile command-line utility for archiving, extracting, listing, and copying files. It was standardized by POSIX.1-2001 to unify and supersede the functionalities of both tar and cpio.

pax can read and write archives in various formats, including both tar (USTAR, POSIX.1-2001) and cpio (old and new). This flexibility makes it an excellent tool for ensuring portability of archives across different Unix-like systems. It operates in four primary modes: list, extract, archive, and copy, determined by the presence or absence of the -r (read) and -w (write) options.

CAVEATS

While pax is a powerful and POSIX-compliant utility, its rich set of options can make it complex to master. Users often need to consult its man page frequently.

Unlike some versions of tar and cpio, pax does not natively support built-in compression (e.g., gzip or bzip2). Compression is typically achieved by piping the output of pax to a compression utility like gzip or bzip2, and decompressing the input accordingly.

MODES OF OPERATION

pax operates in four distinct modes:
1. List Mode (no -r or -w): Lists the contents of an archive.
2. Extract Mode (-r): Reads an archive and extracts its contents to the current directory.
3. Archive Mode (-w): Creates an archive from specified files or standard input.
4. Copy Mode (-rw): Copies a file hierarchy from one location to another, typically to a new directory.

ARCHIVE FORMATS

pax supports reading and writing to several archive formats, making it highly interoperable:
cpio: Reads/writes old ASCII, old binary, and new ASCII cpio formats.
tar: Reads/writes old tar (pre-USTAR) and USTAR (POSIX.1-1988) formats.
pax: The default POSIX.1-2001 format, which is an extension of USTAR, supporting larger files, longer pathnames, and extended attributes.

HISTORY

pax was developed as part of the POSIX.2 standard (IEEE Std 1003.2-1992) to provide a unified archive utility that could handle the various incompatible formats of both tar and cpio. Its goal was to address portability issues and inconsistencies inherent in the existing archiving tools, offering a single, standardized interface for file archiving and exchange across different Unix-like systems. It's designed to be forward and backward compatible with a wide range of archive formats.

SEE ALSO

tar(1), cpio(1), gzip(1), bzip2(1), xz(1), find(1)

Copied to clipboard