Need a fast and efficient way to synchronize files on two systems? Looking for an alternative to FTP / scp / rcp?

rsync is the right tool for it!

rsync's syncing capability makes it an excellent alternative to FTP and other file transfer tools like scp and rcp. Why would one want to use rsync for file transfer? It is efficient (does not transfer files which are already in sync), safe (uses SSH), and offers a lot of useful capabilities that FTP and other tools don't offer easily. Maybe FTP is disabled on the server because of security concerns?

In this tutorial, I will show you some of the most common use cases of rsync:

Upload files

Upload all the contents of the current directory to /home/captain/websites/ahoy on Enter the password for the user when prompted for it.

$ rsync -zvr ./ captain@

Upload files and show the progress

$ rsync -zvr --progress ./ captain@

Delete files that don't exist in the local copy

$ rsync -zvr --delete ./ captain@

Upload files but exclude some files and directory

We want to exclude all files starting with a dot ., and a directory named node_modules.

$ rsync -zvr --exclude=".*/" --exclude node_modules/ ./ captain@

rsync options can be used together

$ rsync -zvr --delete --progress --exclude=".*/" --exclude node_modules/ ./ captain@

Use a public key (.pem file) with rsync

We will used a public key named server-key.pem instead of supplying a password to authenticate. The key is in the current directory in this case.

$ rsync -zvr -e "ssh -i server-key.pem" ./ captain@

Download files

We will download the contents of the directory /home/captain/websites/ahoy on to the current directory. The directory ahoy will be created in the current directory with all its contents.

$ rsync -zvr --progress --exclude=".*/" captain@ ./

Wondering what the options zvr means?

  • z - compress data (faster transfer)
  • v - verbose
  • r - recurse into directories

That should be enough for most basic rsync requirements. If you want to know more, open a terminal and type man rsync.

Note: if you are using scp or rcp, it is high time you switched to rsync - because rsync was written specifically to replace them.