Operations 9 min read

Mastering rsync: Practical Linux Examples for Fast, Reliable File Sync

This guide walks through installing rsync on CentOS and demonstrates nine real‑world examples—including local directory sync, preserving timestamps, remote transfers, avoiding overwrites, progress monitoring, deletion, include/exclude patterns, and size limits—complete with commands, output, and key options.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Mastering rsync: Practical Linux Examples for Fast, Reliable File Sync

rsync is a powerful utility for synchronizing files and directories between local and remote systems. It can operate on both local and remote servers, making it ideal for backups and deployments.

Installation

On CentOS, install rsync with:

[root@localhost ~]# yum -y install rsync

Example 1: Sync two local directories

Use rsync -zvr /var/log/ /root/temp/ to copy files from /var/log/ to /root/temp/ with compression, verbose output, and recursion.

[root@localhost ~]# rsync -zvr /var/log/ /root/temp/
sending incremental file list
btmp
... (output truncated)
sent 516,136 bytes, received 605 bytes, 1,033,482.00 bytes/sec
total size is 5,451,242  speedup is 10.55

-z enables compression.

-v prints detailed information.

-r enables recursive copy.

Local sync output
Local sync output

Example 2: Preserve timestamps with -a

The -a (archive) option combines recursion, symbolic‑link preservation, permission retention, timestamp preservation, and owner/group preservation.

[root@localhost ~]# rsync -azv /var/log/ /root/temp/
... (output shows timestamps retained)
Archive mode preserving timestamps
Archive mode preserving timestamps

Example 3: Sync from local to remote

Both machines must have rsync installed. Use:

[root@localhost ~]# rsync -avz /root/temp/ [email protected]:/root/temp
[email protected]'s password: 
... (files transferred)
Remote sync output
Remote sync output

Example 4: Sync from remote to local

Reverse the source and destination:

[root@localhost ~]# rsync -avz [email protected]:/root/temp /root/temp
[email protected]'s password: 
... (files received)
Pulling files from remote
Pulling files from remote

Example 5: Avoid overwriting newer files with -u

The -u (update) flag skips files that are newer on the destination.

# rsync -avzu [email protected]:/root/temp /root/
... (only older files are copied)
Update option prevents overwrite
Update option prevents overwrite

Example 6: Show progress with --progress

Add --progress to display a live transfer progress bar.

[root@localhost ~]# rsync -avz --progress /root/temp/ [email protected]:/root/temp
Progress display
Progress display

Example 7: Delete extraneous files with --delete

Use --delete to remove files in the destination that no longer exist in the source.

# rsync -avz --delete /root/temp [email protected]:/root
... (files not present in source are deleted)
Deletion of orphaned files
Deletion of orphaned files

Example 8: Include and exclude patterns

Specify patterns to include or exclude particular files or directories.

[root@localhost ~]# rsync -avz --include 'P*' --exclude '*' [email protected]:/var/lib/rpm/ /root/temp/
Include/exclude example
Include/exclude example

Example 9: Limit transferred file size

Use --max-size (or --min-size) to restrict files by size.

[root@localhost ~]# rsync -avz --max-size='1M' [email protected]:/var/lib/rpm/ /root/temp/
Max size limit example
Max size limit example

These examples cover common rsync options—compression, verbosity, recursion, archive mode, update, progress, deletion, pattern matching, and size limits—providing a practical reference for reliable file synchronization and backup on Linux systems.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxBackupSystem Administrationrsyncfile synchronization
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.