Cpio
Encyclopedia
cpio is a general file archiver
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...

 utility and its associated file format
File format
A file format is a particular way that information is encoded for storage in a computer file.Since a disk drive, or indeed any computer storage, can store only bits, the computer must have some way of converting information to 0s and 1s and vice-versa. There are different kinds of formats for...

. It is primarily installed on Unix-like
Unix-like
A Unix-like operating system is one that behaves in a manner similar to a Unix system, while not necessarily conforming to or being certified to any version of the Single UNIX Specification....

 computer operating systems. The software utility was originally intended as a tape archiving program as part of the Programmer's Workbench (PWB/UNIX
PWB/UNIX
The Programmer's Workbench was an early version of the Unix operating system created in the Bell Labs Computer Science Research Group of AT&T....

), 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 and standard output in its operation.

All variants of Unix also support other backup and archiving programs, such as tar
Tar (file format)
In computing, tar is both a file format and the name of a program used to handle such files...

 that has become more widely recognized. The use of cpio by the RPM Package Manager
RPM Package Manager
RPM Package Manager is a package management system. The name RPM variously refers to the .rpm file format, files in this format, software packaged in such files, and the package manager itself...

, in the initramfs program of Linux kernel
Linux kernel
The Linux kernel is an operating system kernel used by the Linux family of Unix-like operating systems. It is one of the most prominent examples of free and open source software....

 2.6, and in Apple Computer's Installer
Installer (Mac OS X)
Installer is an application included in Mac OS X which extracts and installs files out of .pkg packages. It was created by NeXT, and is now maintained by Apple Inc...

 (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.

Operation and archive format

Cpio was originally designed to store backup file archives on a tape device in a sequential, contiguous manner. Cpio does not compress any content, but resulting archives are often compressed using gzip
Gzip
Gzip is any of several software applications used for file compression and decompression. The term usually refers to the GNU Project's implementation, "gzip" standing for GNU zip. It is based on the DEFLATE algorithm, which is a combination of Lempel-Ziv and Huffman coding...

 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
Find
In Unix-like and some other operating systems, find is a command-line utility that searches through one or more directory trees of a file system, locates files based on some user-specified criteria and applies a user-specified action on each matched file...

 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. The file name of an archive is conventionally usually chosen with a .cpio file extension.

Example using find to archive an entire directory tree:

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

Extraction

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


$ cpio -id

The -d flag tells cpio to construct directories as necessary. The -v flag can be used to have file names listed as files are extracted.

Any command line arguments (not option flags) are shell-like globbing-patterns; only files in the archive whose names match one or more of those patterns are copied from the archive. The following example extracts etc/fstab from the archive.

$ cpio -id etc/fstab

List

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

$ cpio -it < 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
File copying
In the realm of computer file management, file copying is the creation of a new file which has the same content as an existing file.All computer operating systems include file copying provisions in the user interface, like the command, "cp" in Unix and "copy" in MS-DOS; operating systems with a...

, initiated with the pass option (-p). This mode combines the copy-out and copy-in steps without actually storing any archive in a file. 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 path given as a command line argument.


$ find . -depth -print0 | cpio --null -pduv new-dir

POSIX standardization

The cpio utility was standardized in POSIX
POSIX
POSIX , an acronym for "Portable Operating System Interface", is a family of standards specified by the IEEE for maintaining compatibility between operating systems...

.1-1988. It was dropped from later revisions, starting with POSIX.1-2001 because of its 8 GB file size limit. The POSIX standardized pax
Pax (program)
pax is an archiving utility created by POSIX and defined by the POSIX.1-2001 standard. By default, it creates archives in ustar format, also defined by the POSIX standard. Rather than sort out the incompatible options that have crept up between tar and cpio, along with their implementations across...

 utility can be used to read and write cpio archives instead.

Implementations

Most Linux
Linux
Linux is a Unix-like computer operating system assembled under the model of free and open source software development and distribution. The defining component of any Linux system is the Linux kernel, an operating system kernel first released October 5, 1991 by Linus Torvalds...

 distributions provide the GNU version of cpio. FreeBSD
FreeBSD
FreeBSD is a free Unix-like operating system descended from AT&T UNIX via BSD UNIX. Although for legal reasons FreeBSD cannot be called “UNIX”, as the direct descendant of BSD UNIX , FreeBSD’s internals and system APIs are UNIX-compliant...

 and Mac OS X
Mac OS X
Mac OS X is a series of Unix-based operating systems and graphical user interfaces developed, marketed, and sold by Apple Inc. Since 2002, has been included with all new Macintosh computer systems...

use the BSD-licensed cpio provided with libarchive

External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK