The trailing slash matters!
A trailing slash on the source means "contents". No slash means "the directory itself". A frequent source of mistakes.
Copies only the differences between trees; --delete mirrors the source into the destination, removing anything extra.
rsync -avzP src/ dst/
sync (changes only, with progress)
rsync -avzP src/ user@host:/dst/
over SSH
rsync -avzn --delete src/ dst/
dry-run a mirror FIRST
rsync -avz --exclude='cache/' src/ dst/
rsync -av --link-dest=/bak/prev src/ /bak/today/
snapshot backup
rsync copies by transferring only the differences — fast for
repeated syncs and large trees. Works locally and over SSH.
The -a flag (archive) means recursion plus preserving
permissions/times/symlinks/owners.
-n (dry-run) shows what would change without writing a single byte to
disk — always check a command with --delete this way before removing the
flag. -a does not include deletion in the destination: without
--delete, rsync only adds and updates files, it never removes anything
extra.
| Option | What it does | Example |
|---|---|---|
-a --archive |
Archive mode (rlptgoD) — recursive, preserves permissions, times, symlinks, ownership. | rsync -a src/ dst/ |
-v --verbose |
Verbose output — which files were transferred. | rsync -av src/ dst/ |
-n --dry-run |
Show what would happen without changing anything on disk. dangerous | rsync -avn --delete src/ dst/ |
--delete |
Delete files in the destination that are missing from the source — mirrors the source exactly. dangerous | rsync -av --delete src/ dst/ |
-z --compress |
Compress file data during the network transfer. | rsync -avz src/ user@host:/dst/ |
-P |
Shorthand for --partial --progress — resumable transfer with a progress bar. | rsync -avP src/ dst/ |
--exclude PATTERN |
Exclude files and directories matching a pattern. | rsync -avz --exclude='cache/' src/ dst/ |
-e command |
Set the remote shell to use, e.g. ssh with a non-default port. | rsync -avz -e 'ssh -p 2222' src/ host:/dst/ |
--bwlimit KBPS |
Limit transfer speed, in KB/s. | rsync -avz --bwlimit=5000 big/ host:/dst/ |
--link-dest DIR |
Hard-link unchanged files from a previous snapshot — saves space in backups. | rsync -av --link-dest=/bak/prev src/ /bak/today/ |
-c --checksum |
Compare files by checksum instead of modification time and size. | rsync -avc src/ dst/ |
Nothing found. Try a shorter query.
A trailing slash on the source means "contents". No slash means "the directory itself". A frequent source of mistakes.
--delete makes dst an exact copy of src. Always run -n (dry-run)
first and check the list. A safety net: --backup --backup-dir=.
The trailing slash on the source (see the slash section above).
Comparison is by mtime and size; if time "drifts" (different filesystems
or time zones), add -c (checksum comparison) or --modify-window=1.
You need -a (or -o/-g/-p individually); for foreign owners, root
rights on the receiving side. On FAT/NTFS, owners are never preserved.
Normal (rsync checks every file). -z helps over a network; for a
one-off archive in a single file, tar is faster.
--delete removes everything in the destination that isn't in the
source, with no confirmation prompt and no trash bin: directories swapped
by mistake will wipe production data in a single run. Always check such a
command with -n (dry-run) and read the list of files to be deleted
before removing the flag. A safety net for important data — --backup
--backup-dir= instead of a direct delete.
Found an inaccuracy? Report an error in the article