How to create and extract cpio archives?

In one of our former posts, we introduced how to use cpio to extract an RPM package. How can we create a cpio archive file?

We can create a cpio archive that contains files and directories using cpio -ov. Examples,

$ cd test

$ ls
file1 file2 file3

$ ls | cpio -ov > /tmp/test.cpio

$ file test.cpio
test.cpio: ASCII cpio archive (pre-SVR4 or odc)

How to extract cpio archive file

To extract a given cpio file, use cpio -idv as below.

$ mkdir output

$ cd output

$ cpio -idv < /tmp/test.cpio

To find more about cpio parameters, run “cpio –help” in command-line.

Share this post

Post Comment