Friday, March 6, 2015

Use rsync on Linux/Mac to move data fast

Here's how to use rsync(1) on a Mac or Linux to move data fast:

rsync –achv[n] {local-dir} {remote-hostname}:{remote-dir}

This will sync the contents of {local-dir} to remote-hostname, {remote-dir}. If you supply the –n option (noted in the square brackets above), it will do a *dry-run only* showing you what will be done – but not yet doing it (very handy to confirm you will be copying the desired stuff to the desired remote location first).

Works for git clones, and any other directories, too. If you want to delete files that exist on {remote-dir} but not {local-dir}, add the delete-after parameter (with two leading dashes), like this:

rsync –achv[n] —delete-after {local-dir} {remote-hostname}:{remote-dir}

Transfers are generally done over ssh, so you’ll have to supply your password when prompted for it.

Rsync can pull as well as push, meaning you can reverse the positions of {local-dir} and {remote-hostname}:{remote-dir}, too. You can even use it to copy files to a different location on the local host if desired, too. Plus it’s very efficient at moving data quickly :-)

No comments:

Post a Comment