Cpio
By Unix / GNU project
Cpio is a Unix archive file format and command-line utility used to copy files into and out of a single archive stream, commonly used for creating initial RAM disk images, software distribution archives, and streaming file collections…
Definition
Cpio is a Unix archive file format and command-line utility used to copy files into and out of a single archive stream, commonly used for creating initial RAM disk images, software distribution archives, and streaming file collections through pipes. It reads a list of file paths from standard input and writes their contents plus metadata into a single archive, or does the reverse when extracting.
Overview
Cpio was developed early in Unix's history to solve the practical problem of bundling many files, along with their permissions and directory structure, into a single stream that could be copied to tape, piped between processes, or transferred as one unit. Unlike tools designed to operate directly on a named set of files, cpio was built around Unix pipes from the start, expecting a list of file paths on standard input, typically generated by another command like find, and producing or consuming an archive stream on standard output or input. Mechanically, cpio operates in three modes: copy-out, which reads file paths and writes them into an archive; copy-in, which reads an archive and extracts files from it; and copy-pass, which copies files directly from one directory tree to another without an intermediate archive file. Each entry in a cpio archive contains a fixed-format header recording the file's metadata, such as permissions, owner, and size, immediately followed by the file's raw contents, with several header format variants existing for compatibility and to support larger files and modern filesystem metadata. Among Unix archiving tools, cpio predates and overlaps with tar, the more commonly used general-purpose archiver; the two solve similar problems but with different conventions, and cpio's pipe-oriented design made it historically preferred for constructing Linux initial RAM disk images, a role it still holds in many bootloaders and kernel build systems. RPM package files also use a cpio archive internally to store the actual file payload alongside RPM's own metadata format, giving cpio continued relevance inside a tool most users interact with at a much higher level. In practice, most users encounter cpio indirectly, through Linux kernel build tooling that assembles initramfs images, through RPM package internals, or through system recovery and backup scripts that favor its pipe-friendly copy-pass mode for directly cloning directory trees. Few developers write cpio archives by hand for everyday file distribution, since tar and newer formats are more commonly used for that purpose. The main trade-offs are that cpio's various header formats have led to compatibility issues between old and new variants, and it lacks convenience features and defaults that make tar friendlier for general-purpose end-user archiving, such as straightforward compression flags and simpler command syntax. Because of this, cpio survives primarily in specific technical roles like initramfs construction and RPM internals rather than as a general file-archiving choice, with most users reaching for tar or zip when manually creating an archive.
Key Features
- Reads file paths from standard input rather than command-line arguments
- Supports copy-out, copy-in, and copy-pass operating modes
- Stores per-file metadata headers followed by raw file contents
- Used internally by RPM package files to store file payloads
- Commonly used to build Linux initial RAM disk (initramfs) images
- Supports copy-pass mode for direct directory-to-directory copying
- Multiple header format variants exist for compatibility and larger files
- Integrates naturally with the Unix pipe model alongside tools like find