Home·Terminal commands

cpio

Archives

Usage

find <path> | cpio -o > <archive.cpio>

An older archiver that takes the list of names to pack from stdin, which is why find usually feeds it; `-o` writes an archive, `-i` extracts one, `-t` lists it, `-H newc` is the portable format initramfs images use, and `--no-absolute-filenames` stops an archive from someone else writing into absolute paths.

Common flags

FlagMeaning
-oCopy-out: build an archive from the names arriving on stdin.
-iCopy-in: extract from an archive on stdin.
-dCreate directories as needed while extracting.
-mPreserve modification times.
-tList the contents instead of extracting.
-vPrint names as they are processed.
-H newcThe portable SVR4 format, and the one initramfs images use.
--no-absolute-filenamesRefuse to extract to absolute paths from an untrusted archive (GNU cpio only).

Examples

find . -depth -print | cpio -ov -H newc > backup.cpio

Archive exactly the file list that find produced.

cpio -idmv < backup.cpio

Extract, creating directories and keeping timestamps.

cpio -itv < backup.cpio

List what is inside first.

Bundling and compressing are separate jobs: tar bundles, gzip shrinks, and .tar.gz is both.

How to read this

  • Square brackets [ ] mark a part you may leave out.
  • An ellipsis … means you can list more than one.
  • Flags are case-sensitive — in some commands -r and -R do different things.

Questions

Q. What does cpio do?

An older archiver that takes the list of names to pack from stdin, which is why find usually feeds it; `-o` writes an archive, `-i` extracts one, `-t` lists it, `-H newc` is the portable format initramfs images use, and `--no-absolute-filenames` stops an archive from someone else writing into absolute paths.

Q. How do I type it?

find <path> | cpio -o > <archive.cpio> — square brackets mark the parts you can leave out.

Q. How many flags are worth knowing?

8 are listed here; the full set is in man cpio. This command sits under Archives.

Related commands

man page: man cpio