13.2.4 Large-Scale Copying

Sometimes you may want to copy one directory to another location. Maybe you’re adding a new hard disk and you want to copy /usr/local to it. There are several ways you can do this.

The first is to use cp. The command cp -a will tell cp to do a copy preserving all the information it can. So, you might use

cp -a /usr/local /destination

However, there are some things that cp -a won’t catch1. So, the best way to do a large copy job is to chain two tar commands together, like so:

tar -cSpf - /usr/local | tar -xvSpf - -C /destination

The first tar command will archive the existing directory and pipe it to the second. The second command will unpack the archive into the location you specify with -C.