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
| Flag | Meaning |
|---|---|
| -o | Copy-out: build an archive from the names arriving on stdin. |
| -i | Copy-in: extract from an archive on stdin. |
| -d | Create directories as needed while extracting. |
| -m | Preserve modification times. |
| -t | List the contents instead of extracting. |
| -v | Print names as they are processed. |
| -H newc | The portable SVR4 format, and the one initramfs images use. |
| --no-absolute-filenames | Refuse to extract to absolute paths from an untrusted archive (GNU cpio only). |
Examples
find . -depth -print | cpio -ov -H newc > backup.cpioArchive exactly the file list that find produced.
cpio -idmv < backup.cpioExtract, creating directories and keeping timestamps.
cpio -itv < backup.cpioList 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