Working with cpio files

Have you ever downloaded a cpio file and wondered what the heck you were going to to with it? I get them from Oracle all the time, and the first time I downloaded one I wasn’t sure what to make of it. In the end, I found that working with cpio files is a breeze, so I thought I would pass on some information that might help.

Ok, just what is a cpio file? A cpio file is an archive, and it is a concatenation of one or more files. Each file in the collection contains a header optionally followed by file contents as indicated in the header. The end of the archive is indicated by another header describing an empty file named TRAILER. There are two types of cpio archives, differing only in the style of the header. ASCII archives have totally printable header information, so, if the files being archived are also ASCII files, the whole archive is ASCII. By default though, cpio writes archives with binary headers.

How do we work with these archive files? Easy. Here is an example, say you download a gzipped cpio file:

  • First, download filename.cpio.gz and use gzip to uncompress.
  • Then use cat filename.cpio | cpio -icd to extract to contents.

There you go, when you are done, the contents of the cpio file should be extracted to where ever you put the cpio file and ran the command. If you want to create an archive, you can pass a file list, like with find to the cpio command and have it create an archive, much like tar does. In my own experience, I prefer tar, but if you have cpio and don’t have tar, it’s better than nothing! Check out this page for more details, a nice article from Linux Journal.

One thought on “Working with cpio files”

Tell me what you are thinking?