There are lots of great tutorials about rsync. This is not intended to be one of them. Instead its a glorified cheat sheet, a reminder of the syntax and switches when I realise I have once again forgotten them.


rsync -azP source/ destination

Fun with flags

  • -a: archive, this combines recursive syncing ( -r ) with the preservation of symbolic links, special and device files, modification times, groups, owners, and permissions.
  • -z: adds compression which reduces network transfer.
  • -P: this is another combination flag, this time covering --progress and --partial giving you both a progress bar and the ability to resume an interrupted transfer.

Trailing slashes:

Add a trailing slash if you want to sync the contents of your source directory to your destination one. Without it the folder itself will be sunk resulting in a destination/source/source-contents folder structure.


Not sure you’ve got your command right? Lets do a dry run to see

rsync -anv source/ destination

Fun with flags:

  • -n: this is the bit that tells rsync to do a dry run
  • -v: verbose, useful if you want to actually know the outcome

Remote sync

One of the main strengths of rsync is the ability to transfer files between local and remote systems

rsync -azP source username@location:destination

If you have ~/.ssh/config set up you can also do

rsync -azP hostname:source destination

Excluding things

Exclude a specific file

rsync -azP --exclude 'file.txt' source destination

or directory

rsync -azP --exclude 'dir' source destination

or just the contents of the directory

rsync -azP --exclude 'dir/*' source destination

multiple files/directories

rsync -azP --exclude={'file.txt', 'dir', '', 'dir2'} source destination

This last one is getting a bit complicated, so if you’re doing this you might whatn to use an exclude file instead:

rsync -azP --exclude-from='exclude-file.txt' source destination

Then in your exclude file: