Create a cpio archive:
localhost% find path/ -depth -print | cpio -oaV > archive.cpio
localhost% find path/ -depth -print | cpio -oaV -O archive.cpio
Create a cpio archive and compress it:
localhost% find path/ -depth -print | cpio -oaV | gzip -c > archive.cpio.gz
Extract a cpio archive:
localhost% cpio -imVd < archive.cpio
localhost% cpio -imVd -I archive.cpio
List the contents of a cpio archive:
localhost% cpio -it < archive.cpio
localhost% cpio -it -I archive.cpio
Use cpio copy-pass to copy a directory structure to another location:
localhost% find path/ -depth -print | cpio -pamVd /new/parent/dir
cpio over SSH
To cpio a local directory, send the output to ssh and feed it to cpio on a remote host:
localhost% find path/ -depth -print | cpio -oaV | ssh user@host ‘cpio -imVd’
Ssh to a remote host, cpio a remote directory, and get its output locally:
localhost% ssh user@host “find path/ -depth -print | cpio -oaV” | cpio -imVd
cpio and rpm
Ever wanted to extract files from an RPM package without installing it? It’s easy. RPMv4 includes a utility called “rpm2cpio”, which creates a cpio stream of files from a given RPM. You can pipe this into cpio just like a regular archive or stream.
List the included files:
localhost% rpm2cpio foo.rpm | cpio -it
./usr/bin/foo
./usr/share/man/man1/foo.1.gz
Extract all files:
localhost% rpm2cpio foo.rpm | cpio -imVd
Extract only the manpage from that package:
localhost% rpm2cpio foo.rpm | cpio -imVd ./usr/share/man/man1/foo.1.gz

Recent Comments