How To Use Cpio In Linux?
cpio is general file archiver used in Linux, Unix and Bsd systems. It is created as a tape archive tool but gained new features along development. Cpio has its own compression format and extension.
Creating Archive With Cpio
We can create archive file with cpio by getting find output.
find . -depth -print | cpio -o > ../perl5.cpio
We use find to list all files in current working path and print all of them to the cpio to compress with its format.
We can create tar archive with cpio by specifying compression algorithm as tar.
$ find . -depth -print | cpio -H tar -o > ../perl5.tar
- -o is output file
- -H tar specifies the compression algorithm will be tar
List Files Inside Cpio Archive
We can list files inside a cpio arhive
$ cpio -i -F ../perl5.cpio
- -F makes listing the files
Write Archive Into A Tape
We can write archive into a tape like below.
$ find . -depth -print | cpio -H tar -F /dev/nst1
Extracting is easy as archiving
$ cpio -i -F /dev/nst1
All files will be extracted to their original paths
Archive Into Remote System Tape
This is very useful and practical solution. Archiving can be done to the remote system tape file like below.
find . -depth -print | cpio -H tar -F /dev/nst1 \
Track Operation With Verbose
Compression operation can be tracked by using verbose option which will give details about compression operation.
$ cpio -v -i -F /dev/nst1
- -v argument makes the command verbose
Supported Compression Algorithms and Formats
`bin' The obsolete binary format.
`odc' The old (POSIX.1) portable format.
`newc' The new (SVR4) portable format, which supports file systems having more than 65536 i-nodes.
`crc' The new (SVR4) portable format with a checksum (Sum32) added.
`tar' The old tar format.
`ustar' POSIX.1 tar format. Also recognizes GNU tar archives, which are similar but not identical.
`hpbin'The obsolete binary format used by HPUX's cpio (which stores device files differently).
`hpodc' The portable format used by HPUX's cpio (which stores device files differently).