Creating and Reading Archives
There was a time when people used to debate whether the BSD
or the System V cpio
(copy in/out) was the better file archive and
At this point, there's no question.
No one ships
the Net (1.33
is widespread, and because there are free versions
there's no reason why you should have to read a cpio
from someone else.
Still, if you're on an older System V machine, you might use
Though we don't give it much air time in this book, here
are a few basics:
To write out an archive, use the -o
option and redirect output
either to a tape device or to an archive file.
The list of files to
be archived is often specified with
but can be generated in other ways-cpio
expects a list of
filenames on its standard input.
find . -name "*.old" -print | cpio -ocBv > /dev/rst8
find . -print | cpio -ocBv > mydir.cpio
To read an archive in, use the -i
option and redirect input
from the file or tape drive containing the archive. The -d
often important; it tells cpio
to create directories as needed
when copying files in.
You can restore all files from the archive
or specify a filename pattern (with wildcards quoted to protect them
from the shell) to select
only some of the files.
For example, the
following command will
restore from a tape drive all C source files:
cpio -icdv "*.c" < /dev/rst8
Subdirectories are created if needed (-d
), and cpio
be verbose (-v
), announcing the name of each file that it
successfully reads in.
To copy an archive to another directory, use the -o
followed by the name of the destination directory.
(This is one of
the nicer features of cpio
.) For example, you could use the
following command to copy the contents
of the current directory (including all subdirectories) to another
find . -depth -print | cpio -pd newdir
There are lots of other options for things like resetting file access
times or ownership or changing the blocking factor on the tape. See
your friendly neighborhood manual page for details. Notice that
options are typically "squashed together" into an option string rather
than written out as separate options.