rsync Cheatsheet - File Sync, Backup & --exclude Options
rsync is the default answer for mirroring trees because it transfers only what differs and can make the destination match the source exactly. That same power is the hazard: with --delete enabled, one mistaken rm on the source, or one mistaken mount, silently empties the destination. Preview every run with -n or --dry-run, and pair it with --itemize-changes so the actual list of transfers, creations and deletions is visible before you commit. The trailing slash is the other classic mistake: src/ copies the contents of the directory, src copies the directory itself, and the difference is one unwanted nesting level. This sheet groups parameters by transfer, display, filtering, backup and archive modes, clarifying what each of -a, -z, --partial and --checksum is actually for rather than listing them as interchangeable flags. Bandwidth matters on a fragile uplink, where --bwlimit and --inplace turn a mirror into something a slow link can survive overnight, and --delete is only safe once the source mount is known to be complete.
Basic Sync 4
rsync -avz ./src /destrsync -avz ./src/ /destrsync -avz user@host:/remote /localrsync -avz /local user@host:/remoteTransfer Options 5
-z, --compress-n, --dry-run--partial--bwlimit=1M-e sshDisplay Options 6
-v, --verbose-q, --quiet--stats-h, --human-readable--progress-PSkip & Filter 5
-u, --update-c, --checksum--exclude=.git--exclude-from=.rsyncignore--include=*.txtBackup Options 4
-b, --backup--suffix=.bak--backup-dir=/backup--deleteArchive Mode 7
-a, --archive-r, --recursive-l, --links-p, --perms-t, --times-g, --group-o, --ownerCommand Examples
Dry-run before deploying
rsync -avzn --delete ./dist/ user@host:/var/www/app/
# Once the listing looks right, drop the n-n is the dry run and it is the single most important flag here. The trailing slash on ./dist/ decides whether the contents or the directory itself is synced, and getting it wrong nests the files one level too deep.
Output
sending incremental file list index.html main.4f3a2b.js deleting old-vendor.js sent 1,204 bytes received 78 bytes 2,563.00 bytes/sec total size is 512,384 speedup is 39.08
Exclude what should not ship, and back up overwrites
rsync -avz --delete \
--exclude=".git" --exclude="node_modules" \
--backup --backup-dir=/var/backup/app \
./dist/ user@host:/var/www/app/--backup together with --backup-dir moves every overwritten file into the named directory, so a rollback is a matter of copying files back. --delete removes extra files on the destination, which is exactly why the dry run comes first.
Resume a large transfer and cap bandwidth
rsync -avzP --bwlimit=1000 user@host:/data/bigfile.iso .-P expands to --partial --progress, so a dropped connection resumes instead of restarting the transfer. --bwlimit is in KB/s: 1000 caps the job near 1MB/s, leaving the rest of the link for real traffic.
Output
sending incremental file list bigfile.iso 1,073,741,824 12% 12.00M 0:01:21 eta 0:01:10
Common Pitfalls
- The trailing slash on the source decides whether you sync the directory or its contents; omitting it creates an extra nesting level.
- --delete removes files absent from the source, so a wrong path is effectively a remote delete — always dry-run with -n first.
- rsync has no built-in backup; an overwritten file is replaced. Use --backup or tar the directory first for anything important.
- By default rsync compares size and mtime, so a touched-but-unchanged file is needlessly retransferred.
- Without -P an interrupted transfer leaves a truncated file that looks complete and will not be repaired on the next run.
Tips
- src/ syncs contents, src syncs the directory itself.
- -a is shorthand for -rlptgoD, preserving nearly all attributes.
- --delete removes extra target files; add -n to simulate first.
- rsync is incremental — only deltas are sent, very efficient.
- Remote transfer uses SSH by default; -e overrides the command.
Official References
Each command links to its official documentation below, so you can verify the latest usage and read deeper.
Maintained by LaoHand
Publicly updated on Jul 19, 2026, continuously proofread against official docs.
Contact Us
Wrong command or description? Send us corrections, business inquiries or product feedback by email.
Contact Us