Use of Rsync Command in Linux with Example

What is Rsync Command In Linux?

The Rsync command in Linux is mostly used to copy and synchronize files and directories remotely along with copying them locally in Linux/Unix system.

With the help of the rsync command, you can easily copy and synchronize your data remotely and locally across the directories, disks, and networks. You can also perform data backups, and mirror between two Linux machines.

In this article, we’re going to walk you through the deep analysis of the rsync command with practical examples so you never have to Google anything about the rsync command.

However, if you’re new to the Linux field, you should first learn the basic Linux Commands, and then you can use the rsync command more efficiently.

Advantages of Rsync Command in Linux

Below are some of the major advantages of using the rsync command;

  • No need to have root privileges to run the rsync command. You can easily use it without root access.

  • it’s the most effective way to sync and copy files from or to a remote server.

  • You can copy links, devices, owners, groups, and permissions which is rare.

  • It’s faster than SCP (Secure Copy) method as it uses a remote-update protocol to transfer files between server to system.

  • It consumes less bandwidth in comparison with any other copying method because rsync uses compression and decompression while sending or/and receiving data from both ends.

How to Use the Rsync Command

# rsync options source destination

Some useful arguments you can use with the rsync command;

  • -r : copies data recursively (but don’t preserve timestamps and permission while transferring data.

  • -a : archive mode, which allows copying files recursively and it also preserves symbolic links, file permissions, user & group ownerships, and timestamps.

  • -z : compress file data.

  • -v : verbose

  • -h : human-readable, output numbers in a human-readable format.

How to Install Rsync In Linux System?

Installation of the Rsync command is fairly simple. You can easily install it by following the below command.

$ sudo apt-get install rsync   [On Debian/Ubuntu & Mint] 
$ pacman -S rsync              [On Arch Linux]
$ emerge sys-apps/rsync        [On Gentoo]
$ sudo dnf install rsync       [On Fedora/CentOS/RHEL and Rocky Linux/AlmaLinux]
$ sudo zypper install rsync    [On openSUSE]

Copy/Sync Files & Directories Locally

Copy/Sync a File on a Local Computer

Use the following command to Sync/Copy a file locally from one location to another.

[getintod@server55 public_html]$ rsync xmlrpc.php /home/getintod/ (Execute command from public_html PWD)
[getintod@server55 public_html]$ cd /home/getintod/               (Jump to the directory where you copied)
[getintod@server55 ~]$ ls                                         (List the contents)
access-logs file2.php newfile2.php public_ftp var
backup getintod newfile3.php public_html wp-login.php
cpanel3-skel home.php newfile.php renamed.htaccess www
etc logs ocartdata ssl xmlrpc.php                                 (File Successfully Copied & Scyned)
example1.php mail perl test.php
example.php newfile1.php perl5 tmp
[getintod@server55 ~]$

Copy/Sync a Directory on a Local Computer

Use the below command to transfer or sync all the files of a directory to a different directory on the same machine. In the below example, /home/getintod/backup directory contains several files and I want to copy all the files present inside the backup directory to another directory named etc.

[getintod@server55 ~]$ rsync -avzh /home/getintod/backup /home/getintod/etc/       (Transfer every files from backup directory to etc directory)
sending incremental file list

sent 376 bytes received 115 bytes 982.00 bytes/sec
total size is 0 speedup is 0.00
Copy Sync files between directories
Sync files between local directories

Copy/Sync Files & Directories to or from a Remote Server

Copy a Directory from a Local Server to a Remote Server

You can simply use the below command to copy/sync a file from a remote server. In the below example, I’m having a couple of files inside the etc directory of my local server, and want to transfer all its content to the remote server. Type the following command to send a directory from a local server to a remote server.

Note: Do not forget to change the path and IP Address with yours. Don’t just copy-paste the command. It won’t work.

[getintod@server55 ~]$ rsync -avzh /home/getintod/etc root@123.456.78.90:/root/
Copy Files from local to remote
Copy Files from local to remote

Copy/Sync a Remote Directory to a Local Machine

[getintod@server55 ~]$ rsync -avzh root@ /home/getintod/etc/
root@'s password:
receiving incremental file list

sent 25 bytes received 186 bytes 24.82 bytes/sec
total size is 0 speedup is 0.00
Copy Files From Remote Server To Local
Copy Files From Remote Server To Local

There are several more ways to use rsync command but these two are the most used and easiest commands to copy/sync files and directories between remote server to local.

I hope now you can easily use the rsync command in Linux. Other than this, if this still didn’t knock your mind then you can visit and open a Free Support Ticket. Our experienced technical team will be happy to assist you. Other than this, you can purchase Reseller hosting or Dedicated hosting from Redserverhost and Save some extra amount as we’re one of the Cheapest Hosting Providers across the Internet.

Now Don’t Say “Who wants to Save Money?”

Everybody Wants!!


Scroll to Top