The cpio command is one of the most commonly used Linux back up
The cpio command has two unusual features
Unlike tar , in which the files to back up are typed in as part
of the command, cpio reads the files to work with from the
standard input (in other words, the screen).
This feature means that cpio must be used as part of a multiple
command or with a redirection pipe. Examples of this usage are
shown in the tables below.
cpio must always be used with one of three flags. Flags are
options that set the mode in which the command runs. Only one
flag can be used at a time, and it must come before any other
options. In addition, the choice of flags limits the options
that can be used. Each flag also has a gnu option that can used
in its place. The gnu option gives a convenient name for each
flag: extract, create, and pass- through.
If you want to know more options and how to
use check cpio
Backing Up using the
To do a backup, use cpio with a search command, such as find .
The basic structure is: find -name string -print | cpio -o
options > directory .
In this example:
The -name option for find lets you search for a string enclosed
in double quotation marks. Metacharacters can be used. The bar
character ( | ) redirects the output of find to cpio .
The -o flag sets cpio to create an archive file for backing up.
The target is a directory.
The > redirection operator redirects files to the location for
the back up. Typically, this location is on a removable device.
Copies all files FROM
one directory TO another WITHOUT changing the
permissions, owner/group or modification date of the
file. Use the following command to verify that all files
-print | wcfind /u/test1 -print | wc
If the number of files
encountered is the same for both directories its safe to
assume that the directories are identical. NOTE: that
the number of blocks allocated to the SOURCE directory
(/u/test) may be larger than the DESTINATION directory
(/u/test1), since compaction of the directory structure
will have occurred at the destination end.
/home/test/.profile < /dev/fd0
Selectively restore the
/home/test/.profile file from floppy
"*.f" "*.c" </dev/fd0
Selectively restore only
the *.f and *.c files from floppy