12 Linux Rsync Options in Linux Explained

In this article, I would show the different rync options to sync file/directories to the destination server. The main advantages of the rsync are:

Speed: Initially copies the whole content between local and remote system. Next, it transfers only the changed blocks or bytes to the destination.

Security: Encrypted form of data that can be transferred using ssh protocol.


Less Bandwidth: rsync uses compression and decompression of the data block by block at both the ends.


#rsync [options] source-path destination-path

1) Rsync Over SSH and Port

With rsync, we can use SSH (Secure Shell) for data transfer, using SSH protocol while transferring our data you can be ensured that your data is being transferred in a secured connection with encryption so that nobody can read your data while it is being transferred over the wire on the internet. Also when we use rsync we need to provide the user/root password to accomplish that particular task, so using SSH option will send your logins in an encrypted manner so that your password will be safe.

a) Copy a File from a Remote Server to a Local Server with SSH

To specify a protocol with rsync you need to give “-e” option with protocol name you want to use. Here in this example, We will be using “ssh” with “-e” option and perform data transfer.

$ rsync -avz -e "ssh -p 922 " cgi@ /home/cgi/km/MONITORING/

b) Copy a File from a Local Server to a Remote Server with SSH

$ rsync -avz -e "ssh -p 922 " TeamViewer_Setup.exe cgi@
Red Hat Enterprise Linux Server release 6.2 (Santiago)

2) Show Progress While Transferring Data with rsync

To show the progress while transferring the data from one machine to a different machine, we can use ‘–progress’ option for it. It displays the files and the time remaining to complete the transfer.

$ rsync -avhz -e "ssh -p 922 " --progress /home/cgi/km/POLP4 cgi@
sending incremental file list

3) Use of –include and –exclude Options with rsync

These two options allows us to include and exclude files by specifying parameters with these option helps us to specify those files or directories which you want to include in your sync and exclude files and folders with you don’t want to be transferred.

Here in this example, rsync command will include those files and directory only which starts with ‘R’ and exclude all other files and directory.

$ rsync -avhz -e "ssh -p 922 " --include 'P*' --exclude '*' cgi@ /home/cgi/km/MONITORING/

4) Set the Max Size of Files to be Transferred

You can specify the Max file size to be transferred or sync. You can do it with “–max-size” option. Here in this example, Max file size is 200k, so this command will transfer only those files which are equal or smaller than 200k

[cgi@server02:km]$ rsync -avhz -e "ssh -p 922 " --max-size='200k' /home/cgi/km/POLP4 cgi@


5) Automatically Delete source Files after successful Transfer

Now, suppose you have a main web server and a data backup server, you created a daily backup and synced it with your backup server, now you don’t want to keep that local copy of backup in your web server. So, will you wait for the transfer to complete and then delete that local backup file manually? Of Course NO. This automatic deletion can be done using ‘–remove-source-files‘ option.

$ rsync -e "ssh -p 922 " --remove-source-files -zvh TeamViewer_Setup.exe cgi@

6) Set Bandwidth Limit and Transfer File

You can set the bandwidth limit while transferring data from one machine to another machine with the help of ‘–bwlimit‘ option. This options helps us to limit I/O bandwidth.

$ rsync -e "ssh -p 922 " --bwlimit=100 -avzh /home/cgi/km/POLP4/ cgi@

7) Enable Compression

In the below command, rsysnc uses –z to enable compression, -v to verbose and -r to recursive. Here the command synchronizes two directories /home/aloft/ and /backuphomedir in the local system.

[root@localhost /]# rsync -zvr /home/aloft/ /backuphomedir
building file list ... done
sent 472 bytes received 86 bytes 1116.00 bytes/sec
total size is 324 speedup is 0.58


8) Preserve File/Directory Attributes

Here we have used –a option to preserve owner and groups, timestamp, symbolic links, permission and recursive mode.

[root@localhost /]# rsync -azvr /home/aloft/ /backuphomedir
building file list ... done


sent 514 bytes received 92 bytes 1212.00 bytes/sec
total size is 324 speedup is 0.53

9) Synchronize local to remote host

Below option allows you to synchronize between local machines to the remote machine. You can see while synchronizing files to another system, it asks for password. While doing synchronization with the remote server, you need to specify user name and IP or Hostname of the remote system.

root@localhost /]# rsync -avz /home/aloft/ azmath@

building file list ... done
sent 514 bytes received 92 bytes 1212.00 bytes/sec
total size is 324 speedup is 0.53

10) Synchronize remote to local host

The below options will synchronizes files from remote to local system.

[root@localhost /]# rsync -avz azmath@ /home/aloft/
building file list ... done
sent 514 bytes received 92 bytes 1212.00 bytes/sec
total size is 324 speedup is 0.53


11) Find the difference in files

Option -avzi helps to find any differences in the files or directories between source and destination.

[root@localhost backuphomedir]# rsync -avzi /backuphomedir /home/aloft/
building file list ... done
cd+++++++ backuphomedir/
>f+++++++ backuphomedir/.bash_logout
>f+++++++ backuphomedir/.bash_profile
>f+++++++ backuphomedir/.bashrc
>f+++++++ backuphomedir/abc
>f+++++++ backuphomedir/xyz


sent 650 bytes received 136 bytes 1572.00 bytes/sec
total size is 324 speedup is 0.41

12) To Take backup

rsync command could be used take linux backup.

You can schedule backup in cron using rsync command,

0 0 * * * /usr/local/sbin/bkpscript &> /dev/null

vi /usr/local/sbin/bkpscript

rsync -avz -e ‘ssh -p2093′ /home/test/ root@

Read Also:

0 (0)
Article Rating (No Votes)
Rate this article
There are no attachments for this article.
There are no comments for this article. Be the first to post a comment.
Full Name
Email Address
Security Code Security Code
Related Articles RSS Feed
Logrotate Example for Custom Logs
Viewed 1439 times since Sun, Jan 12, 2020
How to clear swap memory in Linux
Viewed 641 times since Mon, Nov 23, 2020
Linux – How to check the exit status of several piped commands
Viewed 1892 times since Wed, Jul 25, 2018
rabbitmq Troubleshooting TLS-enabled Connections
Viewed 666 times since Sun, Dec 6, 2020
high swap space utilization in LINUX
Viewed 4878 times since Fri, Jul 13, 2018
Find All Large Files On A Linux System
Viewed 1014 times since Mon, Oct 29, 2018
How setting the TZ environment variable avoids thousands of system calls
Viewed 8272 times since Mon, May 21, 2018
RHEL: Remove existing SAN LUNs
Viewed 12349 times since Sat, Jun 2, 2018
RHEL: Checking HBAs
Viewed 11017 times since Sun, May 27, 2018
How to Install and use Lsyncd on CentOS 7 / RHEL 7 rsync
Viewed 2328 times since Wed, Oct 31, 2018