cpio
Archive utility with stdin file lists
TLDR
Create archive
SYNOPSIS
cpio [options]
DESCRIPTION
cpio (copy in/out) is an archiving utility that reads file lists from stdin and creates or extracts archives. It's commonly used in initramfs images, RPM packages, and for copying directory trees.
The tool operates in three modes: copy-out (create archives), copy-in (extract archives), and pass-through (copy files without archiving). Unlike tar, which accepts file arguments directly, cpio reads filenames from standard input, typically piped from find. This design provides greater flexibility for file selection using find's powerful filtering capabilities.
cpio is the preferred format for Linux initial ramdisk images because of its simplicity and kernel support. RPM packages use cpio internally for storing files. The format supports various archive types and can preserve file metadata including permissions, ownership, and timestamps.
PARAMETERS
-o, --create
Create archive (copy-out mode)-i, --extract
Extract archive (copy-in mode)-p, --pass-through
Copy files (pass-through mode)-t, --list
List archive contents-v, --verbose
Verbose mode-d, --make-directories
Create directories as needed-u, --unconditional
Overwrite files unconditionally-m, --preserve-modification-time
Preserve modification times
MODES
Copy-out (-o):
Create archive from file listCopy-in (-i):
Extract from archivePass-through (-p):
Copy files without archiving
WORKFLOW
find . -name "*.txt" | cpio -o > textfiles.cpio
# Create with verbose output
find . | cpio -ov > backup.cpio
# Extract archive
cpio -i < archive.cpio
# Extract with verbose
cpio -idv < archive.cpio
# List contents
cpio -t < archive.cpio
# Copy directory tree (like cp -r but preserves more)
find /source | cpio -pdm /destination
# Extract specific files
cpio -i "*.conf" < archive.cpio
COMPRESSION
find . | cpio -o | gzip > archive.cpio.gz
# Extract compressed archive
gunzip < archive.cpio.gz | cpio -i
# With bzip2
find . | cpio -o | bzip2 > archive.cpio.bz2
zcat archive.cpio.bz2 | cpio -i
COMMON USES
Initramfs extraction:
cd initramfs
gunzip -c /boot/initramfs.img | cpio -i
CAVEATS
Less intuitive than tar. Requires file list from stdin. No built-in compression. Pathname length limits. Different behavior between GNU and POSIX versions. Not as widely used as tar.
HISTORY
cpio was included in Unix PWB/UNIX in 1977 and became part of POSIX, predating tar and offering more flexible file selection.
