cpio is a general
file archiver
A file archiver is a computer program that combines a number of files together into one archive file, or a series of archive files, for easier transportation or storage. File archivers may employ lossless data compression in their archive formats ...
utility and its associated
file format
A file format is a standard way that information is encoded for storage in a computer file. It specifies how bits are used to encode information in a digital storage medium. File formats may be either proprietary or free.
Some file formats ...
. It is primarily installed on
Unix-like
A Unix-like (sometimes referred to as UN*X or *nix) operating system is one that behaves in a manner similar to a Unix system, although not necessarily conforming to or being certified to any version of the Single UNIX Specification. A Unix-li ...
computer operating systems. The
software utility
Utility software is software designed to help analyze, configure, optimize or maintain a computer. It is used to support the computer infrastructure - in contrast to application software, which is aimed at directly performing tasks that benefit or ...
was originally intended as a tape archiving program as part of the Programmer's Workbench (
PWB/UNIX
The Programmer's Workbench (PWB/UNIX) is an early, now discontinued, version of the Unix operating system that had been created in the Bell Labs Computer Science Research Group of AT&T. Its stated goal was to provide a time-sharing working envir ...
), and has been a component of virtually every Unix operating system released thereafter. Its name is derived from the phrase ''copy in and out'', in close description of the program's use of
standard input
In computer programming, standard streams are interconnected input and output communication channels between a computer program and its environment when it begins execution. The three input/output (I/O) connections are called standard input (stdin ...
and
standard output
In computer programming, standard streams are interconnected input and output communication channels between a computer program and its environment when it begins execution. The three input/output (I/O) connections are called standard input (stdin ...
in its operation.
All variants of Unix also support other backup and archiving programs, such as
tar
Tar is a dark brown or black viscous liquid of hydrocarbons and free carbon, obtained from a wide variety of organic materials through destructive distillation. Tar can be produced from coal, wood, petroleum, or peat. "a dark brown or black bit ...
, which has become more widely recognized.
The use of cpio by the
RPM Package Manager
RPM Package Manager (RPM) (originally Red Hat Package Manager, now a recursive acronym) is a free and open-source package management system. The name RPM refers to the file format and the package manager program itself. RPM was intended primaril ...
, in the
initramfs
In Linux systems, initrd (''initial ramdisk'') is a scheme for loading a temporary root file system into memory, to be used as part of the Linux startup process. initrd and initramfs refer to two different methods of achieving this. Both are comm ...
program of
Linux kernel
The Linux kernel is a free and open-source, monolithic, modular, multitasking, Unix-like operating system kernel. It was originally authored in 1991 by Linus Torvalds for his i386-based PC, and it was soon adopted as the kernel for the GNU ope ...
2.6, and in Apple's
Installer
Installation (or setup) of a computer program (including device drivers and plugins), is the act of making the program ready for execution. Installation refers to the particular configuration of a software or hardware with a view to making it us ...
(
pax
Pax or PAX may refer to:
Peace
* Peace (Latin: ''pax'')
** Pax (goddess), the Roman goddess of peace
** Pax, a truce term
* Pax (liturgy), a salutation in Catholic and Lutheran religious services
* Pax (liturgical object), an object formerly ki ...
) 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
ASCII ( ), abbreviated from American Standard Code for Information Interchange, is a character encoding standard for electronic communication. ASCII codes represent text in computers, telecommunications equipment, and other devices. Because of ...
-based representation.
POSIX abandoned cpio command in favor of
pax
Pax or PAX may refer to:
Peace
* Peace (Latin: ''pax'')
** Pax (goddess), the Roman goddess of peace
** Pax, a truce term
* Pax (liturgy), a salutation in Catholic and Lutheran religious services
* Pax (liturgical object), an object formerly ki ...
command.
History
cpio appeared in
Version 7 Unix
Seventh Edition Unix, also called Version 7 Unix, Version 7 or just V7, was an important early release of the Unix operating system. V7, released in 1979, was the last Bell Laboratories release to see widespread distribution before the commercial ...
as part of the
Programmer's Workbench project.
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
gzip is a file format and a software application used for file compression and decompression. The program was created by Jean-loup Gailly and Mark Adler as a free software replacement for the compress program used in early Unix systems, and in ...
or other external compressors.
Archive creation
When creating archives during the ''copy-out'' operation, initiated with the 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
Find, FIND or Finding may refer to:
Computing
* find (Unix), a command on UNIX platforms
* find (Windows), a command on DOS/Windows platforms
Books
* ''The Find'' (2010), by Kathy Page
* ''The Find'' (2014), by William Hope Hodgson
Film and t ...
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 , 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 tells cpio to construct directories as necessary. Flag (''verbose'') lists file names as they are extracted.
Any remaining command line arguments other than the option flags are shell-like
globbing
In computer programming, glob () patterns specify sets of filenames with wildcard characters. For example, the Unix Bash shell command mv *.txt textfiles/ moves (mv) all files with names ending in .txt from the current directory to the director ...
-patterns; only files in the archive with matching names are copied from the archive. The following example extracts the file ''
/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 (). 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 ), creating directories as needed (), replacing any existing files unconditionally (), while producing a progress listing on standard output ():
$ find . -depth -print , cpio -p -dumv new-path
POSIX standardization
The ''cpio'' utility is standardized in
POSIX
The Portable Operating System Interface (POSIX) is a family of standards specified by the IEEE Computer Society for maintaining compatibility between operating systems. POSIX defines both the system- and user-level application programming interf ...
.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.
The cpio, ustar, and pax file formats are defined by ''POSIX.1-2001'' for the
pax
Pax or PAX may refer to:
Peace
* Peace (Latin: ''pax'')
** Pax (goddess), the Roman goddess of peace
** Pax, a truce term
* Pax (liturgy), a salutation in Catholic and Lutheran religious services
* Pax (liturgical object), an object formerly ki ...
utility, which is currently ''POSIX 1003.1-2008'' compliant, and so it can read and write cpio and ustar formatted archives.
Implementations
Most
Linux distribution
A Linux distribution (often abbreviated as distro) is an operating system made from a software collection that includes the Linux kernel and, often, a package management system. Linux users usually obtain their operating system by downloading one ...
s provide the GNU version of
cpio
.
FreeBSD
FreeBSD is a free and open-source Unix-like operating system descended from the Berkeley Software Distribution (BSD), which was based on Research Unix. The first version of FreeBSD was released in 1993. In 2005, FreeBSD was the most popular ...
and
macOS
macOS (; previously OS X and originally Mac OS X) is a Unix operating system developed and marketed by Apple Inc. since 2001. It is the primary operating system for Apple's Mac computers. Within the market of desktop and lapt ...
use the BSD-licensed
bsdcpio
provided with
libarchive
In computing, tar is a computer software utility for collecting many files into one archive file, often referred to as a tarball, for distribution or backup purposes. The name is derived from "tape archive", as it was originally developed t ...
.
See also
*
List of Unix commands
This is a list of Unix commands as specified by IEEE Std 1003.1-2008, which is part of the Single UNIX Specification (SUS). These commands can be found on Unix operating systems and most Unix-like operating systems.
List
See also
* List of G ...
*
List of archive formats
This is a list of file formats used by archivers and compressors used to create archive files.
Archiving only
Compression only
Archiving and compression
Data recovery
Comparison Containers and compression
Notes
While the original ...
References
External links
cpioin The Single UNIX ® Specification, Version 2, 1997, opengroup.org – indicates applications should migrate to pax utility
in The Open Group Base Specifications Issue 6, 2004 Edition, opengroup.org – indicates cpio as removed
* – 8th Edition of Bell Labs' Unix
* – manual from GNU
*
*
*
*
{{Archive formats
1977 software
Unix archivers and compression-related utilities
Free backup software
Archive formats
File archivers
GNU Project software