Rsync: A Practical Guide to Copying and Synchronizing Files.

Learn how to use rsync for local and remote transfers, monitor progress, resume interrupted copies, mirror directories safely, and tune performance with SSH and bandwidth options.

Rsync: A Practical Guide to Copying and Synchronizing Files.
Image credit: Unknown. Please contact us if you are the owner.


Rsync copies and synchronizes files locally or over a network. It skips unchanged files and can transfer only the changed parts of a file, which often saves time and bandwidth. Its options can preserve file attributes, show progress, and keep partial files for later retries.

Important: Rsync’s behavior depends on its options. A rerun can continue a transfer, but it does not guarantee that the source and destination are identical or that data is free from corruption.



Beginner: copy and sync

1. Copy a local directory

rsync -av source/ destination/

This copies the contents of source/ into destination/, creating the destination directory if needed. The -a option enables archive mode, which preserves common file attributes and recurses through directories; -v prints the files being processed.

The trailing slash matters: source/ means “copy the contents of this directory.” Without it, rsync copies the directory itself into the destination.

2. Copy to a remote host over SSH

rsync -av source/ user@server:/path/

When the destination uses the user@host:path format, rsync normally uses SSH as its remote shell. Replace user, server, and /path/ with your account, host, and destination path.

3. Show progress and keep partial files

rsync -avP source/ user@server:/path/

-P is shorthand for --partial --progress: it displays progress for each file and keeps partially transferred files. Keeping partial files can help with retries, though a subsequent run may need to verify or retransmit data.

To use a non-default SSH port, specify the SSH command:

rsync -avP -e "ssh -p 7325" source/ user@server:/path/

Use the plain command for a quick transfer. Add -e when you need to set SSH options such as a custom port or identity file.

Intermediate: visibility and safer retries

4. Show transfer statistics

rsync -avh --stats source/ user@server:/path/

-h makes sizes easier to read, and --stats prints a summary when the transfer finishes.

5. Keep partial files in a separate directory

rsync -avh --partial-dir=.rsync-partial source/ user@server:/path/

This stores incomplete files in .rsync-partial rather than leaving them in the destination under their final names. Rerunning the command can reuse partial data when possible.

6. Mirror a directory with deletion

rsync -avh --delete source/ destination/

--delete removes destination files that do not exist in the source. This is useful for maintaining a mirror, but a mistaken source or destination path can delete wanted files.

Preview the changes before running a deletion sync:

rsync -avhn --delete source/ destination/

Here, -n means dry-run: rsync reports what it would do without making changes.

Advanced: verification and performance

7. Compare file contents with checksums

rsync -avhc source/ destination/

The -c option makes rsync compare file checksums instead of relying on size and modification time to decide whether files need updating. This reads file contents to calculate checksums, so it can take longer. It does not verify the destination after every transfer.

8. Limit bandwidth

rsync -avh --bwlimit=10M source/ user@server:/path/

This limits rsync’s transfer rate to help avoid saturating a shared connection. Choose a limit that fits your network and workload.

9. Tune SSH for a remote transfer

rsync -avh -e "ssh -p 7325 -o Compression=no" \
  source/ user@server:/path/

This uses SSH on port 7325 and disables SSH compression. Compression may help with compressible text over a slow link; disabling it can reduce CPU use for already-compressed files such as many videos, archives, and images.

10. Combine progress, statistics, and partial-file handling

rsync -avh --info=progress2 --stats \
  --partial-dir=.rsync-partial \
  -e "ssh -p 7325 -o Compression=no" \
  source/ user@server:/path/

--info=progress2 shows overall transfer progress. Review the paths and options before using this as a recurring command, especially if you add --delete.

How to think about rsync

  • Repeatable: Running the same command again usually skips files that already appear up to date.
  • Incremental: Rsync avoids retransmitting unchanged data and can transfer changed portions of files.
  • Recoverable: Keeping partial files can make retries more efficient after an interruption.
  • Option-dependent: A copy is not automatically a mirror. Use --delete only when you want to remove destination-only files.

Quick comparison

TaskSuggested option
Copy files and preserve common attributes-a
See each file as it is processed-v
Display per-file progress and keep partial files-P
Display overall progress--info=progress2
Preview changes without applying them-n
Remove destination-only files--delete
Compare file contents using checksums-c


Rsync is useful for routine copies, remote transfers, and directory mirrors. Choose options based on the job, check the source and destination paths, and use a dry-run to inspect changes before a destructive sync.

rsync is a file synchronization tool designed for efficiency, reliability, and recovery. It uses an incremental transfer model with delta-based comparison of file contents and metadata, enabling partial transfers, safe resumption, and avoidance of redundant data copying.

We hope this was helpful.

Keep Us Caffeinated  ⦿ ⦿
Spotify Logo
↑
SNUBmonkey Join our readers