Tools › Cheat sheets › System Administration › rsync
🔄

rsync cheat sheet

rsync copies only what changed, which makes it ideal for backups and deployments. A trailing slash on the source matters: src/ copies the contents of src, while src copies the folder itself into the destination. Always test with -n (dry run) first.

Click any command to copy it.

Common patterns

CommandWhat it does
rsync -avh src/ dest/Archive copy preserving permissions, times and symlinks, with human-readable sizes.
rsync -avzP src/ user@host:/path/Copy to a remote host over SSH with compression, progress and resume.
rsync -avzP user@host:/path/ ./local/Pull from a remote host.
rsync -avn src/ dest/Dry run: show what would be transferred without doing it.
rsync -av --info=progress2 src/ dest/Show overall transfer progress.

Mirroring and deleting

CommandWhat it does
rsync -av --delete src/ dest/Destructive: Make dest identical to src, deleting files in dest that are not in src. Run with -n first.
rsync -av --delete-after src/ dest/Destructive: Like --delete but removes files only after the transfer succeeds.
rsync -av --remove-source-files src/ dest/Destructive: Move files by deleting each source file after transfer.
rsync -av --backup --backup-dir=../old src/ dest/Keep replaced or deleted files in a backup directory.

Filtering

CommandWhat it does
rsync -av --exclude='*.log' src/ dest/Skip files matching a pattern.
rsync -av --exclude='node_modules/' src/ dest/Skip a directory.
rsync -av --exclude-from=exclude.txt src/ dest/Read exclude patterns from a file.
rsync -av --include='*.jpg' --exclude='*' src/ dest/Copy only files matching a pattern.
rsync -av --max-size=100m src/ dest/Skip files larger than 100 MB.

SSH, speed and checks

CommandWhat it does
rsync -av -e "ssh -p 2222 -i ~/.ssh/key" src/ user@host:/path/Use a custom SSH port and key.
rsync -av --bwlimit=5000 src/ dest/Limit bandwidth to about 5000 KB/s.
rsync -avc src/ dest/Compare files by checksum, not size and time (slower, more precise).
rsync -avu src/ dest/Skip files that are newer in the destination.
rsync -av --partial --append-verify src/ dest/Resume large interrupted transfers.
rsync -av --stats -h src/ dest/Print a summary of what was transferred.
rsync -av --link-dest=../previous src/ dest/Make space-efficient snapshot backups using hard links to the previous snapshot.

Frequently asked questions

Why did rsync create a nested folder?

Because of the trailing slash: rsync src dest creates dest/src, while rsync src/ dest copies the contents of src into dest.

How do I preview what rsync will do?

Add -n (--dry-run), usually together with -v, before running the real command, especially with --delete.

More System Administration cheat sheets

⚙️ systemctl📜 journalctl📦 apt🎩 dnf / yum👥 Users & groups📊 Processes & performance💽 Disks & storage⏱️ Cron expressionsAll System Administration cheat sheets →
Copied to clipboard