How to Use rsync on Linux: Commands, Flags, and Examples
rsync is one of the most useful tools on Linux for copying, syncing, and backing up files. It is fast, reliable, and flexible. Whether you are copying files to another drive, making backups, or syncing data across systems, rsync is often the best tool for the job.
What rsync Does
The name rsync stands for remote sync. It can copy files locally between drives or folders, and it can also sync files to another computer over SSH. One of its biggest advantages is efficiency. After the first run, rsync only transfers changed data instead of copying everything again.
This makes it especially useful for:
- Backing up one drive to another
- Keeping folders in sync
- Resuming interrupted transfers
- Copying large amounts of data safely
- Mirroring files to remote servers
Basic rsync Syntax
rsync [options] source destination
Example:
rsync -av /home/user/Documents/ /mnt/backup/Documents/
This copies the contents of the source folder into the destination while preserving important file information.
Important Note About Trailing Slashes
One of the most important things to understand with rsync is the trailing slash.
rsync -av /source/folder /destination/
rsync -av /source/folder/ /destination/
These two commands do not behave the same way:
/source/foldercopies the folder itself into the destination/source/folder/copies the contents of the folder into the destination
That one slash can make a big difference. Always double check it before running a large transfer.
Common rsync Flags Explained
-a or --archive
This is one of the most commonly used flags. Archive mode preserves permissions, ownership, timestamps, symbolic links, and recursive copying. It is usually the starting point for backup jobs.
rsync -a source/ destination/
-v or --verbose
Shows what rsync is doing as it runs.
rsync -av source/ destination/
-h or --human-readable
Makes sizes easier to read, such as KB, MB, GB, and TB.
rsync -avh source/ destination/
--progress
Displays progress information during transfers, which is especially useful for large files.
rsync -avh --progress source/ destination/
--partial
Keeps partially transferred files if the copy is interrupted. This helps when resuming large transfers.
rsync -avh --partial source/ destination/
--append-verify
Useful for resuming large files. It appends missing data and verifies correctness.
rsync -avh --append-verify source/ destination/
--delete
Deletes files from the destination if they no longer exist in the source. This makes the destination mirror the source.
rsync -av --delete source/ destination/
Warning: --delete can remove files permanently from the destination. Use it carefully, especially if you are not fully sure the source is correct.
-n or --dry-run
Shows what would happen without actually copying or deleting anything. This is one of the safest ways to test an rsync command before running it for real.
rsync -avhn --delete source/ destination/
-z or --compress
Compresses data during transfer. This is mainly useful for network transfers, not local drive-to-drive copies.
rsync -avz user@remote:/path/ /local/path/
-P
This is shorthand for:
--partial --progress
It is very common for large transfers.
rsync -avhP source/ destination/
-r or --recursive
Copies directories recursively. It is included in -a, so you usually do not need it separately when using archive mode.
-u or --update
Skips files that are newer on the destination. Useful when you do not want to overwrite more recent copies.
rsync -avu source/ destination/
-t or --times
Preserves modification times. This is included in -a.
-p or --perms
Preserves file permissions. Also included in -a.
-o and -g
Preserve owner and group. These are included in -a, but ownership preservation may require root privileges.
--info=progress2
Shows overall transfer progress instead of only per-file progress. This is useful for very large jobs with many files.
rsync -avh --info=progress2 source/ destination/
--exclude
Excludes files or directories that match a pattern.
rsync -avh --exclude="*.tmp" --exclude="cache/" source/ destination/
--bwlimit=VALUE
Limits transfer speed. Useful if you want to reduce heat, avoid saturating a connection, or keep the system responsive.
rsync -avh --progress --bwlimit=50M source/ destination/
-e ssh
Tells rsync to use SSH for remote transfers.
rsync -avh -e ssh /local/folder/ user@remote:/backup/folder/
Common rsync Examples
1. Copy a folder to another local drive
rsync -avh /home/user/Documents/ /mnt/backup/Documents/
2. Copy with progress shown
rsync -avhP /mnt/source/ /mnt/destination/
3. Mirror one folder to another
rsync -avh --delete /mnt/source/ /mnt/backup/
4. Test before doing anything
rsync -avhn --delete /mnt/source/ /mnt/backup/
5. Resume a large interrupted copy
rsync -avhP --append-verify /mnt/source/ /mnt/backup/
6. Limit speed to reduce load and heat
rsync -avhP --bwlimit=100M /mnt/source/ /mnt/backup/
7. Exclude unwanted files
rsync -avh --exclude="*.cache" --exclude="lost+found" /mnt/source/ /mnt/backup/
8. Copy to a remote server over SSH
rsync -avh -e ssh /home/user/site/ user@example.com:/var/www/site/
Recommended rsync Commands for Backups
Simple backup command
rsync -avh /source/ /destination/
This is a good default when you want to copy data and preserve metadata.
Backup with progress and resume support
rsync -avhP /source/ /destination/
This is better for large transfers or external drives.
Full mirror backup
rsync -avh --delete /source/ /destination/
This keeps the destination exactly matched to the source.
When to Use rsync Instead of cp
The cp command works fine for simple copies, but rsync is usually better when:
- You want to resume interrupted transfers
- You want progress information
- You need to preserve metadata
- You only want to copy changed files
- You want to mirror one folder to another
- You are copying over a network
Common Mistakes to Avoid
- Using the wrong trailing slash
This can copy a folder itself instead of its contents, or the other way around. - Using
--deletewithout testing first
Always consider running a dry run before using delete. - Forgetting permissions
Some files may requiresudoif you need ownership and permissions preserved properly. - Using compression for local transfers
Compression usually helps over networks, but can slow local drive-to-drive copies. - Assuming rsync means instant transfers
The first run can still take a long time if you are copying many terabytes of data.
Useful Safe Testing Pattern
A good habit is to first test with a dry run:
rsync -avhn --delete /source/ /destination/
If the output looks correct, then run the real command:
rsync -avh --delete /source/ /destination/
Using rsync for External Drives and Large Transfers (Multi-TB)
When working with large drives like 10TB, 12TB, or 18TB disks, rsync behaves a little differently in practice. Transfers can run for hours or even days, and reliability becomes more important than speed.
Recommended Command for Large Drive Transfers
rsync -avhP --partial --append-verify /mnt/source/ /mnt/destination/
This command is ideal for large datasets because:
-apreserves all file metadata-vshows activity-hmakes sizes readable-Pshows progress and keeps partial files--append-verifysafely resumes interrupted files
Resuming After Interruptions
If a drive disconnects or the system shuts down, simply run the same command again:
rsync -avhP --append-verify /mnt/source/ /mnt/destination/
rsync will skip completed files and continue where it left off.
This is one of the biggest advantages of rsync over tools like cp. You never have to restart from scratch.
Prevent Overheating and System Slowdowns
Large transfers can push drives to their limits. If you notice heat issues or instability, limit the transfer speed:
rsync -avhP --bwlimit=100M /mnt/source/ /mnt/destination/
This reduces stress on the drive and can prevent disconnects.
Handling Problematic Drives (I/O Errors)
If a drive has bad sectors or read errors, rsync may stop or skip files. You can make it more tolerant:
rsync -avhP --ignore-errors /mnt/source/ /mnt/destination/
For severely damaged drives, consider using ddrescue first to clone the disk, then run rsync on the recovered data.
Running a Second Pass to Catch Missed Files
After a large transfer completes, it is a good idea to run rsync again to pick up anything missed:
rsync -avh /mnt/source/ /mnt/destination/
This second pass is usually much faster and ensures everything is fully synced.
Verifying Transfer Size
You can quickly compare sizes between drives:
du -sh /mnt/source
du -sh /mnt/destination
If the sizes are close, your transfer likely completed successfully.
Best Practices for Large Transfers
- Use a fan or cooling for external drives during long transfers
- Avoid USB hubs if possible, connect drives directly
- Run transfers on a stable system (avoid sleep mode)
- Always test with
--dry-runbefore using--delete - Expect the first transfer to take a long time
Final Thoughts
rsync is one of the most valuable Linux tools for file transfers, backups, and synchronization. Once you understand the core flags like -a, -v, -h, -P, --delete, and --dry-run, you can handle most backup and copy tasks with confidence.
For many Linux users, rsync becomes the go-to command for moving data between drives, creating backup routines, and safely syncing files. Start with simple commands, test with dry runs when needed, and build from there.