O'Reilly logo

Linux Shell Scripting Cookbook by Sarath Lakshman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Archiving with cpio

cpio is another archiving format similar to tar. It is used to store files and directories in a file with attributes such as permissions, ownership, and so on. But it is not commonly used as much as tar. However, cpio seems to be used in RPM package archives, initramfs files for the Linux kernel, and so on. This recipe will give minimal usage examples of cpio.

How to do it...

cpio takes input filenames through stdin and it writes the archive into stdout. We have to redirect stdout to a file to receive the output cpio file as follows:

Create test files:

$ touch file1 file2 file3

We can archive the test files as follows:

$ echo file1 file2 file3 | cpio -ov > archive.cpio

In this command:

  • -o specifies the output
  • -v is used for printing ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required