rsync is another alternative to cp/scp. Except it has a lot more features. Such as the ability to resume a transfer, copy computer to computer, and has the ability to transfer over ssh with a beautiful progressbar.
rsync <source> <destination>
My main default command that I like to use is:
rsync -aPhz --no-whole-file --inplace <source> <destination> Options: -a is Archive (also gives options -rlptgoD) -r recursive -l copy the symlinks as a symlink -p preserve permissions -g preserve group -o preserve owner -D preseve special/devices -P show a nice Progress bar (best feature ever) and also resumes transfers!
-h make it Human readable -z compress(z) the transfer for us slow internet people. --no-whole-file (sends the whole file as-is, not chunk by chunk) --inplace
(Does not make a temp file first, copies straight to the directory)
Some other options are if your host doesnt run ssh on the standard port 22, you may struggle to get it working, '-e' is your solution
-e 'ssh -p 2234'
Usage for different <source> and <destination>:
These are some of the type of different source and destinations you can use. Make sure that when you are copying directories that you keep the end '/' which tells rsync that it needs to copy the files in that directory, not just an empty directory.
Remote to Local:
rsync email@example.com:/home/bob/ ~/ (This copyies bob's HomeDir to your current HomeDir)
Local to Remote:
rsync -aPhz -e 'ssh -p 33033' /var/www/ serveruser@myserver:/var/www/ (Copies your webserver to your server via port 33033 which is running ssh)
Coyping a Single Directory with no recursive:
rsync -aPhz --no-whole-file --no-r --inplace <source> <destination>
Copy a Single Directory with recursion:
rsync -aPhz --no-whole-file --inplace <source> <destination>
Hopefully you have learnt something today and will use the power of rsync in your next copy procedure!