Skip to Content
This project is a work in progress. If you have any questions or suggestions, feel free to contact me.

Here’s a concise guide on archiving files with cpio in Linux, presented in notes format with a command summary.

Archiving Files with cpio in Linux

  • cpio stands for Copy In and Out.
  • It is used to archive files, copy directories, or extract archives.
  • Reads file names from standard input, not from command-line arguments like tar.

Common Use Cases

  1. Create an archive
  2. Extract files from an archive
  3. List archive contents

File Selection: find + cpio

cpio doesn’t take file names directly — it expects input via pipe or redirect. Usually used with find.

Modes of Operation

ModeFlagDescription
Copy-out-oCreate archive (write files)
Copy-in-iExtract or list from archive
Copy-pass-pCopy files from one dir to another

Creating an Archive (Copy-out mode)

find . -type f | cpio -ov > archive.cpio
  • -o : copy-out (create archive)
  • -v : verbose
  • > : write archive to file

Extracting an Archive (Copy-in mode)

cpio -idv < archive.cpio
  • -i : copy-in (extract)
  • -d : create directories if needed
  • -v : verbose
  • < : read archive from file

Listing Archive Contents

cpio -it < archive.cpio
  • -t : list contents (table of contents)

Copy Files from One Directory to Another (Copy-pass mode)

find . -type f | cpio -pvd /destination/path
  • -p : copy-pass
  • -v : verbose
  • -d : create directories

Compression with gzip

find . -type f | cpio -ov | gzip > archive.cpio.gz

To extract:

gunzip < archive.cpio.gz | cpio -idv

Summary of Common cpio Flags

FlagDescription
-oCopy-out mode (create archive)
-iCopy-in mode (extract/archive view)
-tList archive contents
-dCreate directories as needed
-vVerbose output
-pCopy-pass mode
-uReplace newer files during extract
-mPreserve modification times
Last updated on