cpio

Source: Wikipedia, the free encyclopedia.
cpio
New BSD License
cpio
Filename extension
.cpio
Internet media type
application/x-cpio
Uniform Type Identifier (UTI)public.cpio-archive
Type of formatFile archiver

cpio is a general

standard output
in its operation.

All variants of Unix also support other backup and archiving programs, such as

Installer (pax
) make cpio an important archiving tool.

Since its original design, cpio and its archive file format have undergone several, sometimes incompatible, revisions. Most notable is the change, now an operational option, from the use of a binary format of archive file meta information to an ASCII-based representation.

The POSIX standard abandoned cpio in favor of pax.[citation needed]

History

cpio appeared in Version 7 Unix as part of the Programmer's Workbench project.[2]

Operation and archive format

cpio was originally designed to store backup file archives on a tape device in a sequential, contiguous manner. It does not compress any content, but resulting archives are often compressed using gzip or other external compressors.

Archive creation

When creating archives during the copy-out operation, initiated with the -o command line flag, cpio reads file and directory path names from its standard input channel and writes the resulting archive byte stream to its standard output. Cpio is therefore typically used with other utilities that generate the list of files to be archived, such as the find program.

The resulting cpio archive is a sequence of files and directories concatenated into a single archive, separated by header sections with file meta information, such as filename, inode number, ownership, permissions, and timestamps. By convention, the file name of an archive is usually given the file extension cpio.

This example uses the find utility to generate a list of path names starting in the current directory to create an archive of the directory tree:

$ find . -depth -print | cpio -o > /path/archive.cpio

Extraction

During the copy-in operation, initiated by the command line flag i, cpio reads an archive from its standard input and recreates the archived files in the operating system's file system.

$ cpio -i -vd < archive.cpio

Command line flag d tells cpio to construct directories as necessary. Flag v (verbose) lists file names as they are extracted.

Any remaining command line arguments other than the option flags are shell-like

/etc/fstab
from the archive:

$ cpio -i -d /etc/fstab < archive.cpio

List

The files contained in a cpio archive may be listed with this invocation:

$ cpio -t < archive.cpio

List may be useful since a cpio archive may contain absolute rather than relative paths (e.g., /bin/ls vs. bin/ls).

Copy

Cpio supports a third type of operation which copies files. It is initiated with the pass-through option flag (p). This mode combines the copy-out and copy-in steps without actually creating any file archive. In this mode, cpio reads path names on standard input like the copy-out operation, but instead of creating an archive, it recreates the directories and files at a different location in the file system, as specified by the path given as a command line argument.

This example copies the directory tree starting at the current directory to another path new-path in the file system, preserving files modification times (flag m), creating directories as needed (d), replacing any existing files unconditionally (u), while producing a progress listing on standard output (v):

$ find . -depth -print | cpio -p -dumv new-path

POSIX standardization

The cpio utility is standardized in POSIX.1-1988, but was omitted from POSIX.1-2001 because of its file size and other limitations. For example, the GNU version offers various output format options, such as "bin" (default, and obsolete) and "ustar" (POSIX tar), having a file size limitations of 2,147,483,647 bytes (2 GB) and 8,589,934,591 bytes (8 GB), respectively.[3]

The cpio, ustar, and pax file formats are defined by POSIX.1-2001 for the pax utility, which is currently POSIX 1003.1-2008 compliant, and so it can read and write cpio and ustar formatted archives.

Implementations

Most Linux distributions provide the GNU version of cpio.[4] FreeBSD and macOS use the BSD-licensed bsdcpio provided with libarchive.[5]

See also

References

External links

This page is based on the copyrighted Wikipedia article: Cpio. Articles is available under the CC BY-SA 3.0 license; additional terms may apply.Privacy Policy