Linux rsync Command

Remote Sync - 10 Practical Examples with Detailed Explanations

Example 1

Basic Local Directory Sync

$ rsync -av /source/directory/ /destination/directory/
sending incremental file list ./ file1.txt file2.txt dir1/ dir1/file3.txt sent 2,345 bytes received 89 bytes 4,868.00 bytes/sec total size is 10,240 speedup is 4.21
Synchronizes directories with archive mode (-a) and verbose output (-v). Archive mode preserves permissions, timestamps, symbolic links, and recursively copies directories. The trailing slash on source matters - with slash copies contents, without slash copies the directory itself.
Trailing Slash: /source/ copies contents, /source copies directory
Example 2

Remote Sync Over SSH

$ rsync -avz /local/data/ user@remote:/remote/data/
sending incremental file list ./ file1.txt 1024 100% 0.00kB/s 0:00:00 (xfr#1, to-chk=2/4) file2.txt 2048 100% 1.95MB/s 0:00:00 (xfr#2, to-chk=1/4) sent 3,456 bytes received 67 bytes 2,348.67 bytes/sec
Syncs to remote host over SSH with compression (-z). Automatically uses SSH for transport. Only transfers changed files, making it extremely efficient for incremental backups or updates. Compression reduces bandwidth usage.
Efficiency: Only changed blocks are transferred, not entire files
Example 3

Sync with Progress Display

$ rsync -av --progress /source/ /dest/
sending incremental file list ./ largefile.iso 524,288,000 45% 11.22MB/s 0:00:42
Shows detailed progress for each file being transferred using --progress flag. Displays bytes transferred, percentage complete, transfer speed, and time remaining. Essential for monitoring large transfers or slow connections.
Monitoring: Critical for long-running transfers
Example 4

Dry Run - Preview Changes

$ rsync -av --dry-run /source/ /dest/
sending incremental file list ./ file1.txt file2.txt newfile.txt sent 234 bytes received 20 bytes 508.00 bytes/sec total size is 5,120 speedup is 20.16 (DRY RUN)
Performs a trial run without making any changes using --dry-run (or -n). Shows exactly what would be transferred or deleted. Always recommended before syncing to production systems or using --delete option.
Safety First: Always dry-run before important syncs!
Example 5

Delete Files in Destination

$ rsync -av --delete /source/ /dest/
sending incremental file list deleting oldfile.txt deleting obsolete_dir/ ./ newfile.txt sent 1,234 bytes received 45 bytes 2,558.00 bytes/sec
Makes destination an exact mirror of source by deleting files in destination that don't exist in source. Use with extreme caution as this permanently removes files. Combine with --dry-run first to preview deletions.
DANGER: Files deleted from destination are gone forever!
Example 6

Exclude Patterns

$ rsync -av --exclude='*.log' --exclude='tmp/' /source/ /dest/
sending incremental file list ./ file1.txt file2.txt # *.log files and tmp/ directory not transferred sent 987 bytes received 34 bytes 2,042.00 bytes/sec
Excludes files matching patterns using --exclude flags. Can specify multiple patterns. Useful for skipping cache files, logs, or temporary data. Patterns use wildcards like shell globs.
Common Excludes: *.log, .git/, node_modules/, __pycache__/
Example 7

Bandwidth Limiting

$ rsync -av --bwlimit=1000 /source/ user@remote:/dest/
sending incremental file list ./ file1.txt 1024 100% 0.98kB/s 0:00:01 (xfr#1, to-chk=3/5)
Limits bandwidth usage to specified KB/s using --bwlimit. Prevents rsync from consuming all available bandwidth. Essential on shared connections or when you need bandwidth for other services during sync.
Unit: Limit is in kilobytes per second (KB/s)
Example 8

Preserve Hard Links

$ rsync -avH /source/ /dest/
sending incremental file list ./ file1.txt file2.txt => file1.txt (hardlink) sent 1,456 bytes received 56 bytes 3,024.00 bytes/sec
Preserves hard links using the -H flag. When multiple filenames point to the same inode, rsync recreates these relationships in destination. Important for systems using hard links for space efficiency or backup schemes.
Space Savings: Essential for backup systems using hard links
Example 9

Sync with Checksum Verification

$ rsync -avc /source/ /dest/
sending incremental file list ./ file1.txt # Checksums all files even if size/time match sent 2,345 bytes received 123 bytes 4,936.00 bytes/sec
Forces checksum comparison for all files using -c flag instead of relying on size and modification time. Slower but guarantees files are truly identical. Use when you suspect file corruption or need absolute certainty.
Thorough: CPU-intensive but catches subtle file corruption
Example 10

Backup with Date-Stamped Directory

$ rsync -av --link-dest=/backup/latest /source/ /backup/$(date +%Y%m%d)/
sending incremental file list created directory /backup/20251018 ./ newfile.txt modified.txt # Unchanged files are hard-linked to latest/ sent 1,234 bytes received 234 bytes 2,936.00 bytes/sec
Creates space-efficient incremental backups using --link-dest. Unchanged files are hard-linked to previous backup, only new or changed files consume space. Creates dated backup directories while keeping storage minimal. Perfect for daily backup schemes.
Backup Strategy: Combines incremental efficiency with full backup accessibility