How to use the Rsync command in linux?

Rsync is an important command in Linux and used to synchronize or copy the files and directories within the local and remote server. It is a fast and extraordinarily versatile file copying tool. One of the important features of this command is “Delta Transfer Algorithm (DTA)”. What it means is that it will only copy the changes from the source to destination, instead of copying the whole file or directories. By doing this, it also reduces the amount of data sent over the network. In routine, people are using this command for the daily backups, restoration, and mirroring.

In this article, we will discuss the use of RSYNC commands in various ways.

  1. Copy/Sync file locally

    Let’s assume that we want to copy a file “abc.txt” from one location to etc folder.

    #rsync -zvh abc.txt /etc
  2. Copy/Sync Directory locally

    Let’s assume we want to copy or sync a directory “testdir” to “etc” folder

    #rsync -zavh testdir /etc
  3. Copy files & directories recursively locally

    Let’s assume we have multiple files and directories inside user A’s home directory, use below command to copy files and directories recursively, either use -a or -r option to copy files and directories recursively.

    #rsync -zrvh file2.txt testdir11 /etc 

    You can check those file and directories by using “ls command”.
  4. Copy or sync files and directories from local to remote system Let’s assume that, we want to copy the file “/etc/abc.txt” from local machine to remote machine

    #rsync -zarvh /etc/abc.txt [email protected]***.***.72
  5. Copy or Sync files and directories from the remote machine to the local system

    Let’s assume that we want to copy files and directories from the remote machine to our local system, in the below example I am copying remote file “newfile.txt” in my local machine under /etc folder

    #rsync -zarvh [email protected]***.***.72 /etc
  6. Display Synchronization progress in the rsync command output

    If you want to see the sync or copy progress in the rsync command then use “–progress“,

    #rsync -avh --progress [email protected]_address:/opt/rpms_db /tmp
  7. Delete files at destination if it is not present in the source

    If you have already synced files from source to destination and from a source you have deleted the files then you can force rsync command to delete the files on destination using the –delete option, the example is shown below

    #rsync -avz --delete /opt/rpms_db [email protected]_address:/tmp/rpms_db
  8. Put a limit on file transfer size

    If you don’t want to transfer or copy the large files using rsync then use the option ‘–max-size={specify-size-here}’, incase we don’t want to transfer the files which is more than 1024K, you can do this as per the below command Note: Use symbol M for mb and G for GB.

    #rsync -avz --max-size='500K' /opt/rpms_db [email protected]_address:/tmp

Related Articles

How to install Softaculous on Linux server with cPanel?

Ioncube loader should be installed and enabled on your Linux machine with cPanel before...

How to install mod security on Centos 7.x with apache?

Mod_Security is an open-source web application firewall. It monitors the incoming web request to...

How to Install OpenJDK JAVA 11/8 on Ubuntu?

You can follow this tutorial to install JAVA OpenJDK in all the Ubuntu versions. Following are...

How to Manage Linux VPS (SSD and Traditional) from VPS Management Portal?

We offer SolusVM VPS management portal with SSD Linux VPS and Ttraditional Linux VPS plans....

How to fix rpmdb failed error while processing cPanel update?

You may face the below error while updating cPanel with upcp command or while updating centos...

  • 0 Users Found This Useful

Was this answer helpful?