Here is one of those tips that will let you do a recursive copy of a directory to another location using tar. By using tar and not cp, it will preserve the PERMISSIONS and OWNERSHIPS of all the files it touches.
Simply “cd” to the source location and execute the following command:
tar cvf - . | ( cd /path/to/destination/ ; tar xvf - )
(the commands inside the parentheses get executed in a sub-shell therefore parentheses are also required)
That can also be written as:
tar cvf - . | tar -C /path/to/destination/ xvf -
Another popular method is to use “find” and cpio:
find /old/dir -depth -a -print | cpio -pdumv /new/dir
Thats it!
For even an even easier operation, you can create an alias in your .bashrc file (assuming that you are using bash as your shell of course). Enter this in your .bashrc file:
alias cpbytar='tar cvf - . | ( cd $1 ; tar xvf - )'
Source the .bashrc file, “cd” into the directory you wish to copy then run:
cpbytar destination_directory
That will tar'up and move all the files in the current working directory you might be in to the destination directory that you entered.
All your copied files will keep the same, permissions, ownerships and time stamps. Enjoy!
You could get really sick and declare numeric and alphanumeric starting points and create a script with multiple ranges using cpio. Your boy clarko used to do something like that in his rebuild scripts. Made it copy an entire server in 1/3 the time you could do it with tar pipes.
Yeah, he was a sicko alright,
!!!11!!
Anyway, if I remember correctly, he also opened raw socket connections to the destination host box which that in itself would speed things up considerably. That way, you wont have to worry about the ssh overhead and stuff. I am working on something similar with netcat. Once I am ready, I will let you see it if you are interested.