Copy Entire Contents of a Directory and Preserve Permissions

Posted July 15, 2004 by nifran in Solaris

This tech-recipe describes moving the contents of a directory to another mount point or even another system using tar.

tar preserves permissions on files better than other methods of copying.


To move on the same system, use the following:

cd dir1 && tar -cf - . | (cd dir2 && tar -xpvf -)

dir1 is the directory you want to copy.
dir2 is the directory in which you want the copy to go.

This tar’s the current directory to STDOUT, then changes directory, and untar’s the archive without ever having to find the space for a .tar file.

Use the following to do this across systems via ssh:
cd dir1 && tar -cf - . | ssh system2 "cd dir2 && tar -xpvf -"

The Conversation

Follow the reactions below and share your own thoughts.