The rsync command is one of the most powerful and popular tools in Linux for synchronizing files and directories between different locations. It’s widely used for backups, remote file transfers, and directory synchronization, offering features such as incremental transfers, compression, and file permission preservation.
In this guide, we’ll cover rsync basics along with practical examples to help you master its usage.
Basic Syntax of rsync
rsync [OPTION]... SRC [SRC]... DEST
- SRC: Source file(s) or directory
- DEST: Destination file(s) or directory
Commonly Used rsync Options
| Option | Description |
|---|---|
-a | Archive mode (preserves symbolic links, permissions, timestamps, etc.) |
-v | Verbose output |
-z | Compress file data during transfer |
-P | Show progress and allow resuming partial transfers |
--delete | Delete files from the destination that no longer exist in the source |
-r | Recursively transfer directories |
Examples of rsync in Action
1. Basic File Synchronization
rsync -av /source/directory/ /destination/directory/
-a: Preserves all file attributes-v: Displays detailed progress
2. Synchronizing Files Over SSH
rsync -avz -e ssh /source/directory/ user@remote:/destination/directory/
-e sshtells rsync to use SSH for secure transfer, ideal for remote backups.
3. Excluding Files and Directories
rsync -av --exclude 'file.txt' /source/directory/ /destination/directory/
- Excludes
file.txtwhile syncing everything else.
4. Resuming Incomplete Transfers
rsync -avP /source/directory/ /destination/directory/
-Pcombines--partialand--progressto resume interrupted transfers.
5. Deleting Files in Destination
rsync -av --delete /source/directory/ /destination/directory/
- Ensures the destination mirrors the source by removing files that no longer exist in the source.
6. Syncing Files Between Local and Remote Systems
Local to Remote:
rsync -avz /local/directory/ user@remote:/destination/directory/
Remote to Local:
rsync -avz user@remote:/source/directory/ /local/directory/
7. Backing Up a Directory
rsync -av /source/directory/ /backup/directory/$(date +%F)
- Creates a timestamped backup (e.g.,
/backup/directory/2026-03-07).
8. Testing Commands with Dry Run
rsync -av --delete --dry-run /source/directory/ /destination/directory/
- Preview changes without making them. Remove
--dry-runto execute.
9. Limiting Bandwidth During Transfers
rsync -avz --bwlimit=5000 /source/directory/ user@remote:/destination/directory/
- Limits transfer speed to ~5 MB/s to avoid saturating network bandwidth.
10. Space-Efficient Incremental Backups
rsync -av --link-dest=/backup/previous/ /source/directory/ /backup/$(date +%F)/
- Hard-links unchanged files to previous backups, saving disk space while making each backup appear full.
Watch Out for Trailing Slashes
The presence or absence of a trailing slash on the source path changes rsync behavior:
rsync -av /source/directory/ /destination/directory/
- Copies contents of
/source/directory/into/destination/directory/.
rsync -av /source/directory /destination/directory/
- Copies the directory itself into
/destination/directory/, creating/destination/directory/directory/.
Complementary Commands
- iostat: Monitor disk I/O during large transfers
- df / du: Check available disk space and disk usage before syncing
Conclusion
rsync is a versatile tool that simplifies file synchronization and backup tasks on Linux. By combining the right options, you can efficiently manage local and remote transfers, preserve file integrity, and secure your data.
For secure remote transfers, also check out scp, and for archiving, consider tar.
Related Commands:
scp– Secure copy files between hostscp– Copy files and directoriestar– Archive files and directories
For more advanced options, refer to the manual:
man rsync
And if you'd like to go a step further in supporting us, you can treat us to a virtual coffee ☕️. Thank you for your support ❤️!
We do not support or promote any form of piracy, copyright infringement, or illegal use of software, video content, or digital resources.
Any mention of third-party sites, tools, or platforms is purely for informational purposes. It is the responsibility of each reader to comply with the laws in their country, as well as the terms of use of the services mentioned.
We strongly encourage the use of legal, open-source, or official solutions in a responsible manner.


Comments