🎁 New User? Get 20% off your first purchase with code NEWUSER20 Register Now →
Menu

Categories

rsync Command

Intermediate SSH & Remote man(1)

Fast and versatile file synchronization tool

👁 13 views 📅 Updated: Mar 15, 2026
SYNTAX
rsync [OPTION]... SOURCE... DESTINATION

What Does rsync Do?

rsync is a fast, versatile file copying tool that synchronizes files and directories between local and remote locations. It is the gold standard for backups, deployments, and file synchronization because it only transfers changed portions of files.

rsync uses a delta-transfer algorithm to send only differences between source and destination, dramatically reducing bandwidth usage. It supports compression, SSH encryption, include/exclude patterns, and dry-run mode.

rsync is essential for automated backups, server migrations, deployment pipelines, and maintaining synchronized copies of directories across systems.

Options & Flags

OptionDescriptionExample
-a Archive mode (preserves permissions, timestamps, symlinks, recursion) rsync -a /src/ /dest/
-v Verbose output rsync -av /src/ /dest/
-z Compress data during transfer rsync -avz /local/ user@remote:/path/
--delete Delete files in destination not in source rsync -av --delete /src/ /dest/
-n Dry run — show what would be done without doing it rsync -avn --delete /src/ /dest/
--exclude Exclude files matching pattern rsync -av --exclude='*.log' /src/ /dest/
-P Show progress and enable partial (resume) rsync -avP large_dir/ user@server:/backup/
-e Specify remote shell (e.g., SSH with custom port) rsync -avz -e 'ssh -p 2222' /src/ user@server:/dest/
--backup Make backups of replaced files rsync -av --backup --backup-dir=/old /src/ /dest/

Practical Examples

#1 Sync directories locally

Copies the web root to backup, preserving all attributes. Note the trailing slash on source.
$ rsync -av /var/www/html/ /backup/www/

#2 Sync to remote server

Synchronizes the web directory to a remote server with compression.
$ rsync -avz /var/www/ user@server:/var/www/

#3 Backup with deletion

Creates an exact mirror — files deleted from source are also deleted from backup.
$ rsync -av --delete /data/ /backup/data/

#4 Dry run before sync

Shows what would be transferred or deleted without actually doing anything.
$ rsync -avn --delete /src/ /dest/

#5 Exclude patterns

Syncs project excluding log files and node_modules.
$ rsync -av --exclude='*.log' --exclude='node_modules' /project/ /backup/

#6 Sync with progress

Shows transfer progress and file-by-file details. Supports resume on interruption.
$ rsync -avP /large-dir/ user@server:/backup/

#7 Deploy via SSH

Deploys application code excluding environment files and storage.
$ rsync -avz --delete --exclude='.env' --exclude='storage/' /app/ user@prod:/var/www/app/

Tips & Best Practices

Trailing slash matters: rsync /src/ /dest/ copies contents of src into dest. rsync /src /dest/ copies the src directory itself into dest. The trailing slash on source changes behavior significantly.
Always dry-run first: Use rsync -avn (or --dry-run) before any sync with --delete to preview what will be removed. This prevents accidental data loss.
Incremental backups: Use --link-dest for space-efficient incremental backups: rsync -a --link-dest=/backup/yesterday /data/ /backup/today/

Frequently Asked Questions

How do I sync files to a remote server?
Use rsync -avz /local/path/ user@server:/remote/path/. The -a preserves attributes, -v is verbose, -z compresses during transfer.
What does the trailing slash mean in rsync?
rsync /src/ copies the CONTENTS of src. rsync /src copies the DIRECTORY src itself. Always double-check slashes.
How do I only copy changed files?
rsync does this automatically — it is its core feature. It compares file sizes and modification times, only transferring differences.

Master Linux with Professional eBooks

Curated IT eBooks covering Linux, DevOps, Cloud, and more

Browse Books →