Creating and Reading Archives
There was a time when people used to debate whether the BSD
or the System V
(copy in/out) was the better file archive and
At this point, there's no question.
No one ships
the Net (
is widespread, and because there are free versions
there's no reason why you should have to read a
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
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-
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
option and redirect input
from the file or tape drive containing the archive. The
often important; it tells
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 (
be verbose (
), announcing the name of each file that it
successfully reads in.
To copy an archive to another directory, use the
followed by the name of the destination directory.
(This is one of
the nicer features of
.) 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.