Rsync: Copying files across machines

Rsync is usually faster than scp. Here are what the options mean:

  • -a: option treats the entire path as an archive (recursively downloads everything and preserves file attributes)
  • -z: compress file before copying it over just for the file transfer. This minimizes the amount of data that needs to be transferred over and speeds up file copy.
  • -P: show progress indicator; also, resume from any previous partial downloads

As far as I can tell, here are the benefits of scp over this approach:

  • It does not require any special software running on the remote machine. Rsync requires that the remote machine has rsync too. In my experience, I’ve never seen this be an issue. Most linux systems will have rsync installed.
  • scp is secure by default. You need to ask rsync to use ssh for it to be secure.

If we were being very semantic and you wanted to just copy a file over, scp is the right tool and does not try to do any of the smart optimizations to speed up the copy process that rsync does - like checking mod-time and size of local file before deciding if it should be copied over from the remote machine. rsync is a tool for synchronizing directories across machines. However, for most situations - it works quite well as a replacement for scp.

Update: Turns out you could use scp -C option to enable compression on scp to bring it more in line with the -z option of rsync. Rsync still has the other benefits such as preserving file attributes, optimizing what to transfer based on local presence of the file etc.




Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store