Professional Documents
Culture Documents
Menu
As the name suggests, rsync command is used to sync (or copy) files and directories locally
and remotely. One of the important feature of rsync is that it works on “delta transfer
algorithm”, means it will only sync or copy the changes from source to destination instead
of copying the whole file which ultimately reduce amount of data sent over network. Linux
geeks generally use rsync command to manage day to day backup, mirroring, and
restoration activities. It uses remote shell like SSH while synchronizing the files from local
machine to remote machine and any user in the system can use rsync command as it does
not require root or sudo privileges..
In this article we will discuss 17 useful rsync command examples in Linux, these examples
will help specially Linux beginners to manage their sync, mirroring, and backup task more
efficiently.
Rsync command is available for all UNIX and Linux like operating systems. When we do
minimal installation of CentOS & RHEL OS then rsync package is not part of default
https://www.linuxtechi.com/rsync-command-examples-linux/ 1/35
24/03/2023, 08:31 17 useful rsync (remote sync) Command Examples in Linux
installation, so to install rsync on CentOS & RHEL, run the beneath yum command
In Debian Like operating Systems (Ubuntu & Linux Mint) use below apt command to install
rysnc tool,
Some of the commonly used options in rsync command are listed below:
https://www.linuxtechi.com/rsync-command-examples-linux/ 2/35
24/03/2023, 08:31 17 useful rsync (remote sync) Command Examples in Linux
–progress show the sync progress during transfer
In above we have used the options like -z for compression, -v for verbose output and -h for
human readable output.
https://www.linuxtechi.com/rsync-command-examples-linux/ 3/35
24/03/2023, 08:31 17 useful rsync (remote sync) Command Examples in Linux
As we can see “pkumar” directory is created on destination folder and its contents are also
copied. In the above example if use trail / after source folder (/home/pkumar/) then rsync
command will not create pkumar directory on destination but it will copy the contents only.
https://www.linuxtechi.com/rsync-command-examples-linux/ 4/35
24/03/2023, 08:31 17 useful rsync (remote sync) Command Examples in Linux
Note : In rsync command -a option is used for archiving during the copy or sync and apart
from archiving -a option is also used for followings:
https://www.linuxtechi.com/rsync-command-examples-linux/ 6/35
24/03/2023, 08:31 17 useful rsync (remote sync) Command Examples in Linux
sent 484 bytes received 15.45M bytes 1.07M bytes/sec
total size is 16.37M speedup is 1.06
[root@gateway ~]#
Above command will automatically create a folder “rpms_db” under the /tmp folder in our
local machine.
https://www.linuxtechi.com/rsync-command-examples-linux/ 7/35
24/03/2023, 08:31 17 useful rsync (remote sync) Command Examples in Linux
https://www.linuxtechi.com/rsync-command-examples-linux/ 8/35
24/03/2023, 08:31 17 useful rsync (remote sync) Command Examples in Linux
2.84M 100% 35.22MB/s 0:00:00 (xfr#6, to-chk=18/25)
rpms_db/httpd-tools-2.4.6-88.el7.centos.x86_64.rpm
92.50K 100% 1.13MB/s 0:00:00 (xfr#7, to-chk=17/25)
rpms_db/postfix-2.10.1-7.el7.x86_64.rpm
2.56M 100% 14.44MB/s 0:00:00 (xfr#17, to-chk=7/25)
rpms_db/samba-4.8.3-4.el7.x86_64.rpm
696.47K 100% 3.71MB/s 0:00:00 (xfr#19, to-chk=5/25)
rpms_db/samba-client-libs-4.8.3-4.el7.x86_64.rpm
5.07M 100% 19.90MB/s 0:00:00 (xfr#20, to-chk=4/25)
rpms_db/samba-common-4.8.3-4.el7.noarch.rpm
210.98K 100% 844.42kB/s 0:00:00 (xfr#21, to-chk=3/25)
rpms_db/samba-common-libs-4.8.3-4.el7.x86_64.rpm
167.51K 100% 667.70kB/s 0:00:00 (xfr#22, to-chk=2/25)
rpms_db/samba-common-tools-4.8.3-4.el7.x86_64.rpm
458.38K 100% 1.77MB/s 0:00:00 (xfr#23, to-chk=1/25)
rpms_db/samba-libs-4.8.3-4.el7.x86_64.rpm
282.33K 100% 1.09MB/s 0:00:00 (xfr#24, to-chk=0/25)
Read Also : 14 SCP Command Examples to Securely Transfer Files in Linux
Let’s suppose we want to copy the directory structure of “/home/pkumar” from local
machine to remote machine (192.168.1.29) under /opt folder.
https://www.linuxtechi.com/rsync-command-examples-linux/ 9/35
24/03/2023, 08:31 17 useful rsync (remote sync) Command Examples in Linux
root@gateway ~]# rsync -av -f"+ */" -f"- *" /home/pkumar root@192.168.1
root@192.168.1.29's password:
building file list ... done
………………………………………………
pkumar/
So in this situation rsync command can used as it can start copying the file from where it
left off or terminated, or in other words rsync can transfer the files which are partially
copied using scp command. Example is shown below,
https://www.linuxtechi.com/rsync-command-examples-linux/ 10/35
24/03/2023, 08:31 17 useful rsync (remote sync) Command Examples in Linux
1,921,843,200 100% 18.47MB/s 0:01:39 (xfr#1, to-chk=0/1)
[root@gateway ~]#
https://www.linuxtechi.com/rsync-command-examples-linux/ 12/35
24/03/2023, 08:31 17 useful rsync (remote sync) Command Examples in Linux
In the below example want to copy the files of type pdf and rpm and exclude png file types.
https://www.linuxtechi.com/rsync-command-examples-linux/ 13/35
24/03/2023, 08:31 17 useful rsync (remote sync) Command Examples in Linux
speed.
Let’s assume we want to set maximum data transfer rate (speed) is 600 KB/s with rsync,
example is shown below
https://www.linuxtechi.com/rsync-command-examples-linux/ 14/35
24/03/2023, 08:31 17 useful rsync (remote sync) Command Examples in Linux
total size is 11,648,064 speedup is 24,116.07
[root@gateway ~]#
As per above command output, there is difference in file called “projects.txt” on destination.
Following are the meaning of the keywords in above output,
That’s all from this tutorial, in case these examples you to understand rsync command more
efficiently then please do share your feedback and comments
Also Read: How to Rotate and Compress Log Files in Linux with Logrotate
Harry
November 20, 2019 at 5:19 pm
very helpful.
thanks
Reply
https://www.linuxtechi.com/rsync-command-examples-linux/ 15/35
24/03/2023, 08:31 17 useful rsync (remote sync) Command Examples in Linux
Vignesh
December 22, 2019 at 3:22 am
I was looking for a way to copy a folder with files worth 155 GB in Linux. This is
exactly what I was looking for. Thanks for taking the time to write this article with
detailed examples.
Reply
Tom
April 7, 2020 at 6:13 am
Thanks, using this article I create a simple script to copy my data from Unraid
server to a Synology NAS.
Reply
KRS
July 7, 2020 at 8:37 am
Please be advised that the -z flag for compression only compresses the files during
the transfer and then uncompresses them at the destination, so it’s totally
unnecessary when using rsync locally or even inside a gigabit network.
Reply
Zoran Miljkovic
November 21, 2020 at 9:36 am
https://www.linuxtechi.com/rsync-command-examples-linux/ 16/35
24/03/2023, 08:31 17 useful rsync (remote sync) Command Examples in Linux
Hi, could you explain the use of “p” in “-a equal to following options -rlptgoD”?
Reply
Zoran Miljkovic
November 21, 2020 at 9:56 am
Reply
Jacob L
March 18, 2021 at 4:37 pm
I have used rsync for years and always avoided using -z for copies on the same
system.
I have assumed compressing it then uncompressing it would only add CPU
overhead since the limiting factors would be the read and write speeds of the disk(-
s) involved. Am I missing something?
Reply
Pradeep Kumar
March 19, 2021 at 2:39 am
Hi Jacob,
You are correct when we are dealing with large file or huge file.Rsync with -z
option can add CPU overhead.
https://www.linuxtechi.com/rsync-command-examples-linux/ 17/35
24/03/2023, 08:31 17 useful rsync (remote sync) Command Examples in Linux
Reply
Paul Inglsmit
February 9, 2023 at 2:29 pm
Reply
Leave a Comment
Name *
Email *
Website
Post Comment
https://www.linuxtechi.com/rsync-command-examples-linux/ 18/35
24/03/2023, 08:31 17 useful rsync (remote sync) Command Examples in Linux
https://www.linuxtechi.com/rsync-command-examples-linux/ 19/35
24/03/2023, 08:31 17 useful rsync (remote sync) Command Examples in Linux
Recent Posts
https://www.linuxtechi.com/rsync-command-examples-linux/ 20/35
24/03/2023, 08:31 17 useful rsync (remote sync) Command Examples in Linux
https://www.linuxtechi.com/rsync-command-examples-linux/ 21/35
24/03/2023, 08:31 17 useful rsync (remote sync) Command Examples in Linux
https://www.linuxtechi.com/rsync-command-examples-linux/ 22/35
24/03/2023, 08:31 17 useful rsync (remote sync) Command Examples in Linux
https://www.linuxtechi.com/rsync-command-examples-linux/ 23/35
24/03/2023, 08:31 17 useful rsync (remote sync) Command Examples in Linux
https://www.linuxtechi.com/rsync-command-examples-linux/ 24/35
24/03/2023, 08:31 17 useful rsync (remote sync) Command Examples in Linux
https://www.linuxtechi.com/rsync-command-examples-linux/ 25/35
24/03/2023, 08:31 17 useful rsync (remote sync) Command Examples in Linux
https://www.linuxtechi.com/rsync-command-examples-linux/ 26/35
24/03/2023, 08:31 17 useful rsync (remote sync) Command Examples in Linux
https://www.linuxtechi.com/rsync-command-examples-linux/ 27/35
24/03/2023, 08:31 17 useful rsync (remote sync) Command Examples in Linux
https://www.linuxtechi.com/rsync-command-examples-linux/ 28/35
24/03/2023, 08:31 17 useful rsync (remote sync) Command Examples in Linux
https://www.linuxtechi.com/rsync-command-examples-linux/ 29/35
24/03/2023, 08:31 17 useful rsync (remote sync) Command Examples in Linux
https://www.linuxtechi.com/rsync-command-examples-linux/ 30/35
24/03/2023, 08:31 17 useful rsync (remote sync) Command Examples in Linux
https://www.linuxtechi.com/rsync-command-examples-linux/ 31/35
24/03/2023, 08:31 17 useful rsync (remote sync) Command Examples in Linux
https://www.linuxtechi.com/rsync-command-examples-linux/ 32/35
24/03/2023, 08:31 17 useful rsync (remote sync) Command Examples in Linux
https://www.linuxtechi.com/rsync-command-examples-linux/ 33/35
24/03/2023, 08:31 17 useful rsync (remote sync) Command Examples in Linux
https://www.linuxtechi.com/rsync-command-examples-linux/ 34/35
24/03/2023, 08:31 17 useful rsync (remote sync) Command Examples in Linux
© 2023 LinuxTechi
https://www.linuxtechi.com/rsync-command-examples-linux/ 35/35