Remote File Synchronization in Linux

Remote Synchronization (rsync) is a powerful command-line utility in Linux that efficiently synchronizes files and directories between two locations, whether locally on the same machine or remotely between different systems. It is widely used by system administrators for copying, syncing, backup, and mirroring data.

The rsync command operates by designating one machine as the source and another as the destination. What makes rsync particularly efficient is its delta transfer algorithm, which compares files and transfers only the differences between source and destination after the initial full transfer.

Features

  • Delta Transfer Algorithm Only transfers file differences, making subsequent syncs faster and more bandwidth-efficient

  • Compression Automatically compresses data during transfer to save bandwidth

  • Preservation Maintains file permissions, timestamps, and symbolic links

  • Quick-check Algorithm Uses file size and modification time to quickly identify changes

Syntax

Local to Local Transfer

rsync [OPTIONS] SOURCE DESTINATION

Local to Remote Transfer

rsync [OPTIONS] SOURCE [USER@]HOST:DESTINATION

Remote to Local Transfer

rsync [OPTIONS] [USER@]HOST:SOURCE DESTINATION

Common Options

Option Description
-a Archive mode: recursive copy with permissions, timestamps, and symbolic links preserved
-r Recursive copy (without preserving permissions)
-v Verbose output showing detailed progress
-z Compress data during transfer
-P Show progress during transfer
-p Preserve file permissions
-t Preserve modification times

Examples

Local File Transfer

Transfer a file from current directory to another local directory

rsync -v test_backup.gz test/
ubuntu@server:~$ rsync -v test_backup.gz test/
sending incremental file list
test_backup.gz

sent 828,331,571 bytes  received 35 bytes  66,266,528.48 bytes/sec
total size is 828,129,280  speedup is 1.00

Local Directory Synchronization

Recursively copy all files from one directory to another

rsync -av test/ demo/
ubuntu@server:~$ rsync -av test/ demo/
sending incremental file list
./
abc.xhtml
hello.xhtml
login.xhtml
success.xhtml

sent 73,972 bytes  received 247 bytes  148,438.00 bytes/sec
total size is 73,012  speedup is 0.98

Local to Remote Transfer

Copy a backup file to a remote server

rsync -v my_backupfile.zip ubuntu@192.168.1.100:/tmp/
ubuntu@server:~$ rsync -v my_backupfile.zip ubuntu@192.168.1.100:/tmp/
my_backupfile.zip

sent 828,331,547 bytes  received 35 bytes  61,357,894.96 bytes/sec
total size is 828,129,280  speedup is 1.00

Remote to Local Transfer

Copy a file from remote server to local machine

rsync -av ubuntu@192.168.1.100:test.txt tmp/
ubuntu@server:~$ rsync -av ubuntu@192.168.1.100:test.txt tmp/
receiving incremental file list
test.txt

sent 43 bytes  received 1,988,966 bytes  1,326,006.00 bytes/sec
total size is 1,988,385  speedup is 1.00

Remote Directory Synchronization

Synchronize an entire directory from remote server

rsync -av ubuntu@192.168.1.100:demo tmp/
ubuntu@server:~$ rsync -av ubuntu@192.168.1.100:demo tmp/
receiving incremental file list
demo/
demo/abc.txt

sent 47 bytes  received 200 bytes  164.67 bytes/sec
total size is 53  speedup is 0.21

Key Points

  • rsync automatically creates destination directories if they don't exist

  • The first transfer copies the entire file; subsequent transfers only sync differences

  • Password authentication may be required for remote transfers unless SSH keys are configured

  • The trailing slash (/) in directory paths affects how rsync handles the transfer

Conclusion

rsync is an essential tool for efficient file synchronization in Linux environments. Its delta transfer algorithm and compression capabilities make it ideal for backup operations, data mirroring, and maintaining synchronized copies across multiple systems while minimizing bandwidth usage.

Updated on: 2026-03-17T09:01:38+05:30

563 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements