Celeb Glow
updates | March 03, 2026

cpio basic extract command, 'tar xzvf' equivalent?

I've received a Unix software distribution as a compressed cpio file. What's the best command to extract the files?

2

4 Answers

gzip -cd foo.cpio.gz | cpio -idmv
  • i : extract (input)
  • d : create directories
  • m : preserve mtime
  • v : verbose
0
mkdir archive
cd archive
zcat ../archive.cpio.gz | cpio -idmv --no-absolute-filenames

While this is an old question, it shows up high on Google, so I thought I might update it. I agree with the accepted answer in general, but you should add "--no-absolute-filenames" unless you are intending to overwrite important system files on your machine. Also, personally, I prefer "zcat" over "gzip -cd" or "gunzip -c".

Finally, note that you need to run cpio as root (e.g. sudo) if you are extracting a root filesystem that contains device nodes.

This Wikipedia page on cpio has some good notes.
For more details, refer to the cpio manual.

A link from the same Wikipedia page discusses comparison with tar archives.
And, here is an example of using cpio with the tar format.

For example, to extract the archived contents of /etc/httpd/ to the current directory, creating subdirectories ./etc/httpd/

mkdir restored-etc-httpd
cd restored-etc-httpd
zcat archive.cpio.gz | cpio -idmv --no-absolute-filenames "*etc/httpd/*"

The accepted answer and Matt's were both helpful to me but I was stumped for a while because of three details:

  1. The matching pattern needs to be quoted to work as a pattern :P
  2. The option --no-absolute-filenames must precede the pattern on the command line
  3. Since that option removes the leading / from filenames, the matching pattern must also omit the leading /

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy