Introduction
cpio is a Unix archive format from the 1970s, a little older than
tar and simpler. The cpio
command reads a list of file names and copies the files into or out of an archive. It is
seldom used directly today, but it sits inside common formats: the Linux kernel’s
initramfs is a cpio archive, RPM packages carry their files as a compressed cpio
archive, and macOS installer packages hold a cpio payload.
Structure
An archive is a series of entries, each a header, the file name and the file’s data.
The last entry is named TRAILER!!! and has no data. There are several
header formats, told apart by the magic at the start of each header:
| Format | Magic | Header | Notes |
|---|---|---|---|
| Old binary | 070707 octal as a 16-bit number (C7 71 or 71 C7) | 26 bytes | 16-bit fields in the writer’s byte order; name and data padded to an even length |
| odc (portable ASCII) | 070707 as text | 76 bytes | POSIX.1: fields as octal text; no padding |
| newc (SVR4) | 070701 as text | 110 bytes | fields as 8 hexadecimal digits; header with name, and data, padded to 4 bytes |
| crc | 070702 as text | 110 bytes | newc with a simple checksum of the data |
Each header gives the inode number, mode, owner, group, link count, modification time, device numbers, name length and file size. Hard links are recognised by a shared inode number. Every field of every header format is on the headers page.
Not described
Re-checked on 2026-11-13 against libarchive’s cpio(5) and the POSIX pax specification.
Known, not yet covered
- Reference: the GNU cpio and Solaris extensions that cpio(5) leaves as “XXX”: the HP-UX device-number layout, Solaris ACL and extended-attribute entries, and the GNU variants (for example its handling of hard-link data and “crc”-format variants). They are documented in those implementations, which were not read.
Links
Software
- GNU cpio – the GNU
cpiocommand (Linux, macOS) - bsdcpio and bsdtar – libarchive’s commands, built into macOS (macOS, Linux, Windows)
- 7-Zip – free archiver that extracts cpio archives (Windows)
Developers
- libarchive – reads and writes every cpio format (C)
Reference
- pax – the POSIX description, which includes the odc cpio format