Copy entire contents of a directory and preserve permissions
Sometimes it’s needed to move 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, do the following:
cd dir1 && tar -cf – . | (cd dir2 && tar -xpvf -)
dir1 is the directory you want to copy
dir 2 is the directory you want the copy to go into.
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.
You can also do this across systems via ssh:
cd dir1 && tar -cf – . | ssh system2 “cd dir2 && tar -xpvf -”





