Q. Can you explain how do I use cpio under Linux / UNIX?
A. GNU cpio is a tool for creating and extracting archives, or copying files from one place to another. It handles a number of cpio formats as well as reading and writing tar files. cpio command works just like tar, only better.
As I said earlier, cpio works like tar but it can read input from the "find" command. This is nifty feature. For example you can find out all *.c files and backup with cpio command.# find / -name "*.c" | cpio -o --format=tar > c-file.backup.tarYou can also specify file name using -F option:
# find / -iname "*.pl" | cpio -o -H tar > perl-files.tar# find / -iname "*.pl" | cpio -o -H tar -F perl-files.tarWhere,
- -o: Create archive
- -F: Archive filename to use instead of standard input or output. To use a tape drive on another machine as the archive.
- -H format: Specify file format to use.
- -i: Restore archive
You can extract archive with the following command:# cpio -i -F perl-files.tarYou can list file inside archive i.e. list contents of the cpio file with following command:# cpio -it -F perl-files.tarYou can write archive of /home to tape (drive /dev/nst0), type the following command:# find /home | cpio -o -H tar -F /dev/nst0Restore backup using following command:# cpio -i -F /dev/nst0Backup /home dir, to remote system tape drive:# find /home | cpio -o -H tar -F user@backup.nixcraft.in:/dev/nst0 --rsh-command=/usr/bin/ssh
Featured Articles:
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- My 10 UNIX Command Line Mistakes
- Linux: 20 Iptables Examples For New SysAdmins

- 25 PHP Security Best Practices For Sys Admins
- The Novice Guide To Buying A Linux Laptop
- 10 Greatest Open Source Software Of 2009
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- Top 20 OpenSSH Server Best Security Practices
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Linux Video Editor Software
Facebook it - Tweet it - Print it -


{ 5 comments… read them below or add one }
Very nice info
can u pls tell how can i use bzip2 compression with it?
Thanks
Hi all,
i’m new to unix can any help me full and incremental back scripts for Solaris 10 and RHEL 6 .
Thnaks in advance.
`pax` aims to replace both `tar` and `cpio` as it can read from both, and write to both. In can read files from `find`, too, and can operate in pass-through mode, like `cpio`
Nicely done. Very helpful. You can also redirect the cpio output to thumb drive
find /home/jsmtih cpio -ov > media//backup.cpio
You are awesome! Just wanted to make your day better :)