rsync Commands

rsync commands cheatsheet.

Sync folders locally or over SSH, mirror, and back up — only copying what changed. Tap to copy.

Basic sync
rsync -av source/ dest/Sync a directory (archive mode, verbose)
rsync -avz source/ user@host:/dest/Sync to a remote server, compressed
rsync -avz user@host:/src/ ./dest/Pull from a remote server
rsync -av --delete source/ dest/Mirror: remove files missing from source
Preview & progress
rsync -avn source/ dest/Dry run — show what would change
rsync -avP source/ dest/Show progress and keep partial files
rsync -avh source/ dest/Human-readable sizes in the output
rsync -av --stats source/ dest/Print a transfer summary at the end
Exclude & remote options
rsync -av --exclude='*.log' src/ dst/Skip files matching a pattern
rsync -av --exclude-from=skip.txt src/ d/Read exclude patterns from a file
rsync -av -e 'ssh -p 2222' src/ host:/d/Use a non-standard SSH port
rsync -av --bwlimit=2000 src/ dst/Throttle bandwidth (KB/s)
Backups & resume
rsync -avz --partial src/ host:/d/Resume interrupted transfers
rsync -a --link-dest=../prev curr/ new/Incremental backup using hard links
rsync -avz --delete-after src/ host:/d/Mirror, deleting only after copying
Trailing slash matters: source/ copies the contents of source into dest, while source (no slash) copies the folder itself into dest. Always test a mirror with -n (dry run) before adding --delete.

Why rsync instead of cp or scp

rsync copies files, but its trick is that it only transfers the differences — on a second run it skips everything that hasn't changed, making repeat syncs and backups dramatically faster than copying from scratch. The workhorse flag is -a ("archive"), which preserves permissions, timestamps, symlinks and ownership in one letter. Add -v for verbose output and, for network transfers, -z to compress data in flight. rsync -avz is the combination you'll type most.

The trailing-slash gotcha

The single most common rsync confusion is the trailing slash on the source. rsync -av source/ dest/ copies the contents of source into dest, whereas rsync -av source dest/ copies the source folder itself, creating dest/source/. It's worth pausing on this every time, because getting it wrong nests a folder one level too deep. The destination's trailing slash, by contrast, doesn't change the behaviour.

Mirroring and backups

Two options turn rsync into a backup tool. --delete makes the destination an exact mirror by removing files that no longer exist in the source — powerful, and exactly why you should preview with -n (dry run) first so a wrong path doesn't wipe the wrong folder. For versioned backups, --link-dest points at the previous backup and hard-links unchanged files, so each snapshot looks complete but only the changed files take up new space. rsync works seamlessly over SSH, so the same commands back up to a remote server. Pair it with the SSH commands for the connection and tar for one-off archives.

FAQ

What does the trailing slash mean in rsync?
On the source, a trailing slash (source/) copies the folder's contents into the destination; without it (source), the folder itself is copied, creating dest/source/. The destination's trailing slash makes no difference.
How do I preview rsync changes before running them?
Add -n (or --dry-run): rsync -avn source/ dest/ lists exactly what would be transferred or deleted without touching anything. Always do this before using --delete.

More cheatsheets