From: Andrew Tefft (teffta@engr.dnet.ge.com)
Date: 07/01/93


From: Andrew Tefft <teffta@engr.dnet.ge.com>
Subject: how-to: copying directory hierarchies
Date: 1 Jul 1993 09:46:57 -0400

Here is a hint that many of us Unix users are familiar with. It comes
from the tar man page, which is not present (just a yucky info file) in SLS, so
many Linuxers who are new to Unix never find out about it. Every once in a
while I see a question on how to copy directory hierarchies (say, duplicate an
entire partition), and it's easy to do with tar:

cd srcdir; tar cf - . | (cd destdir; tar xvfBp -)

More creative uses of tar command options can be used. For example, you
can use the "+one-file-system" option so that tar won't traverse mount
points -- if you use this option when tar'ing /, it shouldn't copy
any filesystems you have mounted, such as /usr.

Other experts may have their favorite options too. BTW the info on
gnu tar says the B option on the extract is assumed when reading from
a pipe, so it should not be needed.

So for a practical application, let's say you want to copy your /usr
filesystem to a new disk on /dev/hdb1. First mount /dev/hdb1 on a temporary
mount point, usually /mnt (assuming you have made the partitions and put
a filesystem on /dev/hdb1). Then:

cd /usr; tar cf - . | (cd /mnt; tar xvfBp -)

and watch everything get copied.