Author: Steve Borho
Email: steve@meridian.com
Web Page: http://www.meridian.com
Date Submitted: Wed, Apr 29, 1998
Status: Updated Entry
Entry Updated: 5

Releases: all
Platform: all
Category:  Common Problems with Linux\Unix Commands
Category Listing:  copying directories

Issue

What is the best way to copy an entire directory tree from one place to another?

Response

The recommended method of copying directory trees from one place to another is
to use cpio. It handles symlinks and device files much better than tar or
cp and is the ONLY way to copy the root directory.

Standard syntax is as follows:

cd /source_dir ; find . -depth -print | cpio -pamd /dest_dir

The find command generates an exhaustive list of filenames and pipes them to
cpio which in turns copies each file to the destination tree.

Say, for instance, that you have a RedHat 5.0 system that you would like to
move to a new hard-drive. You would take the following steps:


Assuming your current Linux root directory resides on /dev/hda1 and the new
hard-drive is /dev/hdb.
NOTE: the RedHat rescue floppy adds /mnt/bin and /mnt/sbin and /mnt/usr/bin
to your default PATH, so it is important to mount the old root parition
onto a directory named / mnt, otherwise you have no 'find' or 'cpio' or
'vi' to run.

References

Of course the cpio man page has a complete description of 
available options.