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.

SysOps·31 commands·Last updated 2026-07-19
rsyncSyncBackupFile Transfer

Basic Sync 4

rsync -avz ./src /dest
Sync src directory to dest (including src itself)
rsync -avz ./src/ /dest
Sync src contents to dest (not src itself)
rsync -avz user@host:/remote /local
Pull from remote to local
rsync -avz /local user@host:/remote
Push from local to remote

Transfer Options 5

-z, --compress
Compress data during transfer
-n, --dry-run
Simulate, no actual transfer
--partial
Keep partially transferred files (resume)
--bwlimit=1M
Limit bandwidth to 1MB/s
-e ssh
Use SSH as the transport

Display Options 6

-v, --verbose
Verbose output
-q, --quiet
Quiet mode
--stats
Show transfer statistics
-h, --human-readable
Human-readable numbers
--progress
Show progress
-P
Same as --partial --progress

Skip & Filter 5

-u, --update
Skip files newer on the target
-c, --checksum
Skip by checksum (not time+size)
--exclude=.git
Exclude the .git directory
--exclude-from=.rsyncignore
Read exclude rules from a file
--include=*.txt
Include specific files

Backup Options 4

-b, --backup
Back up overwritten files
--suffix=.bak
Backup file suffix
--backup-dir=/backup
Back up to a given directory
--delete
Delete extra target files (mirror)

Archive Mode 7

-a, --archive
Archive mode (-rlptgoD)
-r, --recursive
Recurse into directories
-l, --links
Preserve symlinks
-p, --perms
Preserve permissions
-t, --times
Preserve modification times
-g, --group
Preserve group
-o, --owner
Preserve owner

Command Examples

Dry-run before deploying

rsync -avzn --delete ./dist/ user@host:/var/www/app/ # 确认输出无误后去掉 n

-n 是 dry-run,最关键的一步。/dist/ 末尾的斜杠决定同步的是目录内容还是目录本身——写错会把文件多套一层。

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 配合 --backup-dir 把被覆盖的旧文件挪到指定目录,回滚有据可查。--delete 会删目标端多余文件,务必先 dry-run。

Resume a large transfer and cap bandwidth

rsync -avzP --bwlimit=1000 user@host:/data/bigfile.iso .

-P 等于 --partial --progress,断了重连能续传。--bwlimit 单位是 KB/s,1000 即约 1MB/s,避免打满链路影响其他业务。

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