As a developer who's worked with rsync for years across dozens of projects, I've discovered it's much more than just a file copy utility. The --remove-source-files
flag is just the tip of the iceberg. Here's my curated collection of advanced techniques that will supercharge your file operations.
For web deployments, this is my go-to pattern:
rsync -avz --delete /build/ user@server:/app/tmp/
ssh user@server "mv /app/live /app/old && mv /app/tmp /app/live"
The --delete
ensures removed files are cleaned up, while the atomic moves prevent partial updates.
When working with remote servers, avoid saturating your connection:
rsync -avz --bwlimit=5000 source/ user@remote:/destination/
This limits transfer speed to 5000 KB/s (5 MB/s), perfect for background syncs.
For absolute data integrity, skip the timestamp checks:
rsync -avc source/ destination/
The -c
flag forces checksum comparison rather than relying on file size/modification times.
Network drop? No problem with partial file resuming:
rsync -avz --partial --progress source/ user@remote:/destination/
The --partial
flag keeps partially transferred files instead of deleting them.
Complex exclusion patterns become simple:
rsync -avz --exclude='*.tmp' --exclude='cache/' source/ dest/
Or use an exclusion file for complex patterns:
rsync -avz --exclude-from='exclude-list.txt' source/ dest/
Need just the folder structure?
rsync -av -f"+ */" -f"- *" source/ empty_dir/
This copies only directories while excluding all files.
Always verify with --dry-run
before running destructive commands:
rsync -avn --delete source/ destination/
The -n
shows what would happen without making changes.
For slow connections, compress and optimize:
rsync -avz --compress-level=9 --size-only source/ user@remote:/dest/
Higher compression level (--compress-level=9
) trades CPU for bandwidth.
The classic -a
flag is actually a combination of:
-rlptgoD (recursive, links, perms, times, group, owner, devices)
For most use cases, -a
does exactly what you need.
rsync's filtering system is incredibly powerful:
rsync -av --filter="merge filter-rules" source/ dest/
Where filter-rules might contain complex include/exclude patterns.
Rsync has become my go-to tool for all file transfer operations. What started as a simple sync utility has evolved into my Swiss Army knife for data management. The real power lies in its extensive flag options that most users never fully explore.
This flag transforms rsync from a copy tool to a move operation:
rsync -av --remove-source-files /source/ /destination/
Files are deleted from source only after successful transfer verification.
Network drop? No problem with partial transfers:
rsync --partial --progress -avz /source/ user@remote:/destination/
Limit network impact during business hours:
rsync --bwlimit=1000 -av /source/ /destination/
For critical transfers where you need absolute certainty:
rsync -cav /source/ /destination/
Clean transfers without dotfiles:
rsync -av --exclude=".*" /source/ /destination/
Always test before executing:
rsync -nav /source/ /destination/
Optimize for slow connections:
rsync -avz -e ssh /source/ user@remote:/destination/
Mirror source exactly:
rsync -av --delete /source/ /destination/
For large transfers:
rsync -av --progress /source/ /destination/
When dealing with non-standard ports:
rsync -av -e "ssh -p 2222" /source/ user@remote:/destination/
Here's my production-grade rsync command for database backups:
rsync --partial --progress --bwlimit=5000 -cavz \
--exclude="*.tmp" --exclude="cache/*" \
-e "ssh -p 2222 -i ~/.ssh/backup_key" \
/var/lib/mysql/ backup@remote:/backups/mysql/
The key is combining flags to match your specific use case. Rsync's flexibility means there's always a perfect combination for your transfer needs.