A Beginner's Guide to Rsync: The Ultimate File Synchronization Tool
rsync
(remote sync) is a fast and versatile file-copying tool that can:
cp
but with more control).Unlike a simple cp
or scp
command, rsync
only transfers the differences between files, making it much faster for large datasets.
The general structure of an rsync
command is:
rsync [options] source destination
| Option | Description |
|--------|-------------|
| -a
| Archive mode (preserves permissions, ownership, timestamps) |
| -v
| Verbose output (shows progress) |
| -z
| Compress data during transfer (faster over networks) |
| -h
| Human-readable output (shows sizes in KB, MB, etc.) |
| -P
| Shows progress and allows resuming interrupted transfers |
| -n
| Dry run (simulates what would happen without making changes) |
| --delete
| Deletes files in destination that don’t exist in source |
| -e ssh
| Uses SSH for remote transfers (secure) |
To copy a directory (/home/user/docs
) to a backup location (/backup
):
rsync -av /home/user/docs /backup
To sync a local folder to a remote server:
rsync -avz -e ssh /local/path/ user@remote-server:/remote/path/
If you want the destination to exactly match the source (deleting extra files):
rsync -av --delete /source/ /destination/
To skip specific files or directories (e.g., node_modules
or .tmp
files):
rsync -av --exclude='node_modules' --exclude='*.tmp' /source/ /destination/
To avoid saturating your network (e.g., limit to 500 KB/s):
rsync -avz --bwlimit=500 /source/ user@remote:/destination/
To see what rsync
would do without actually copying anything:
rsync -avn /source/ /destination/
rsync
is an incredibly powerful tool for file synchronization and backups. Whether you're managing local backups, deploying files to a remote server, or keeping directories in sync, rsync
provides efficiency and flexibility.
Pro Tip: Combine rsync
with cron
to automate regular backups!
Have you used rsync
before? What’s your favorite use case? Let me know in the comments!