Copying a Directory Tree with tar

You can use tar to back up an entire directory tree to another location while preserving permissions and ownerships. Here's a sample command:

[email protected]:/somedir # tar cf - . |(cd /another/dir/; tar xvf -)

This creates a new directory structure under /another/dir/ containing a mirror of the current directory. It does this by creating a tar file on standard output (the - symbol), and then changing directory to the destination and unpacking the tar file that it sees on standard input. This is not quite as neat as the pax command discussed later in the chapter, which does the same thing.

Was this article helpful?

0 0

Post a comment