Your first five minutes with rsync
Five things, in this order: the shape of the command, how to see what it will do before it does it, the one detail that trips up everybody, how to copy to another machine, and how to delete safely.
1. Every rsync command has the same shape
rsync [options] SOURCE DESTINATION
Source first, destination second — the same order as cp. Two options do most of the
work, and you will see them together constantly:
-
-a(archive) — recurse into directories and preserve what matters: modification times, permissions, symbolic links and, where you have the privileges for it, ownership. Use it by default. It includes-t, and leaving-tout is the most common reason rsync re-copies files it should have skipped. -
-v(verbose) — name the files as they transfer. One-vis useful; more than one produces so much output it can get in rsync's way.
2. Find out what it will do first
--dry-run (or -n) runs the whole comparison and prints exactly what
would be transferred and deleted, while changing nothing. It costs one extra run and it is the
habit that separates a confident rsync user from a nervous one.
rsync -av --dry-run photos/ /media/backup/photos/
sending incremental file list
./
2026-08-11-canberra.jpg
sent 1,544 bytes received 27 bytes 3,142.00 bytes/sec
total size is 18,204,193 speedup is 11,587.65 (DRY RUN) Happy with the list? Run the same command again without --dry-run:
rsync -av photos/ /media/backup/photos/ 3. The trailing slash changes the meaning
This is the one that catches everybody, and it catches them silently — nothing errors, you just get a directory you did not expect. A trailing slash on the source means “the contents of this directory”. No trailing slash means “this directory itself”.
# WITH a trailing slash: the CONTENTS of photos/ go into backup/
rsync -av photos/ /media/backup/
/media/backup/2026-08-11-canberra.jpg # WITHOUT it: the FOLDER photos itself goes into backup/
rsync -av photos /media/backup/
/media/backup/photos/2026-08-11-canberra.jpg How to never get this wrong. Write both paths with a trailing slash and say
what you mean literally: photos/ into backup/photos/. If you ever find
a backup/photos/photos/, this is why. A trailing slash on the destination makes no
difference.
4. Copying to another machine
Put user@host: in front of a path and rsync runs itself over SSH. Nothing extra to
configure — if you can ssh to the machine, and rsync is installed on both ends, this
works.
rsync -av photos/ you@server.example.com:/srv/backup/photos/
you@server.example.com's password:
sending incremental file list Reverse the arguments to pull instead of push:
rsync -av you@server.example.com:/srv/logs/ ./logs/ 5. Making the destination match exactly
By default rsync only adds and updates; a file you deleted from the source stays at the
destination forever. --delete removes those leftovers, which is what you want from a
mirror and emphatically not what you want if you have the arguments the wrong way round.
# ALWAYS with --dry-run the first time
rsync -av --delete --dry-run photos/ /media/backup/photos/
sending incremental file list
deleting 2019-old-holiday.jpg
total size is 18,204,193 speedup is 11,587.65 (DRY RUN) --delete deletes at the destination, based on the source. Swap the
two paths by accident and rsync will faithfully make your real photos match your empty backup
disk. Run it with --dry-run first, every time, and read the deleting
lines before you commit.
That is enough to use rsync for real work. Next: Recipes covers complete commands for specific jobs — including compressing and resuming a big transfer, and excluding files from it — the reference has every option there is, and Get help is there if something has already gone wrong.