全部博文(76)
分类:
2010-03-03 19:15:56
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.tar
You 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.tar
Where,
You can extract archive with the following command:# cpio -i -F perl-files.tar
You can list file inside archive i.e. list contents of the cpio file with following command:# cpio -it -F perl-files.tar
You can write archive of /home to tape (drive /dev/nst0), type the following command:# find /home | cpio -o -H tar -F /dev/nst0
Restore backup using following command:# cpio -i -F /dev/nst0
Backup /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