DevOps Essentials

View on GitHub



rsync - faster, flexible replacement for rcp





rsync [OPTION]… SRC [SRC]… rsync://[USER@]HOST[:PORT]/DEST

rsync [OPTION]… SRC



rsync [OPTION]… rsync://[USER@]HOST[:PORT]/SRC [DEST]


rsync is a program that behaves in much the same way that rcp does, but has many more options and uses the rsync remote-update protocol to greatly speed up file transfers when the destination file is being updated.

The rsync remote-update protocol allows rsync to transfer just the differences between two sets of files across the network connection, using an efficient checksum-search algorithm described in the technical report that accompanies this package.

Some of the additional features of rsync are:

OTHER Description

It efficiently copies and sync files to or from a remote system.

Supports copying links, devices, owners, groups and permissions.

It’s faster than scp (Secure Copy) because rsync uses remote-update protocol which allows to transfer just the differences between two sets of files. First time, it copies the whole content of a file or a directory from source to destination but from next time, it copies only the changed blocks and bytes to the destination.

Rsync consumes less bandwidth as it uses compression and decompression method while sending and receiving data both ends.



This following command will sync a single file on a local machine from one location to another location. Here in this example, a file name backup.tar needs to be copied or synced to /tmp/backups/ folder.

[root@tecmint]# rsync -zvh backup.tar /tmp/backups/
created directory /tmp/backups
sent 14.71M bytes  received 31 bytes 3.27M bytes/sec
total size is 16.18M  speedup is 1.10

This command will sync a directory from a local machine to a remote machine. For example: There is a folder in your local computer “rpmpkgs” which contains some RPM packages and you want that local directory’s content send to a remote server, you can use following command.

[root@tecmint]$ rsync -avz rpmpkgs/ root@
root@'s password:
sending incremental file list
sent 4993369 bytes  received 91 bytes 399476.80 bytes/sec
total size is 4991313  speedup is 1.00

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.

[root@tecmint]# rsync -avzhe ssh root@ /tmp/
root@'s password:
receiving incremental file list
sent 30 bytes  received 8.12K bytes  1.48K bytes/sec
total size is 30.74K  speedup is 3.77

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.

[root@tecmint]# rsync -avzhe ssh --progress /home/rpmpkgs root@

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

[root@tecmint]# rsync -avze ssh --include 'R*' --exclude '*' root@ /root/rpm

Automatically delete source files after complete successfull transfer.

[root@tecmint]# rsync --remove-source-files -zvh backup.tar /tmp/backups/