Rsync is an important Linux command that synchronizes or copies the files and directories within the local and remote servers; it is a fast and extraordinarily versatile file-copying tool. 

One of the essential features of this command is the Delta Transfer Algorithm (DTA), which only copies the changes from the source to the destination, instead of copying the whole file or directories. Using the DTA, we can reduce the amount of data sent over the network. People generally use this command for daily backups, restoration, and mirroring.

This article will discuss the multiple uses of the Rsync command.

Use 1: Copy/Sync File locally

Let’s assume we want to copy the abc.txt file from one location to the etc folder

# rsync -zvh abc.txt /etc

Use 2: Copy/Sync Directory locally

Let’s assume we want to copy or sync the testdir directory to the etc folder.

# rsync -zavh testdir /etc

Use 3: Copy files and directories recursively locally

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

# rsync -zrvh file2.txt testdir11 /etc 

You can check those files and directories by using the ls command.

Use 4: Copy or sync files and directories from the local to the remote system

Let’s assume that we want to copy the /etc/abc.txt file from the local machine to the remote machine.

# rsync -zarvh /etc/abc.txt root@173.***.***.72

Use 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 example given below, we will copy the remote newfile.txt file to our local machine under the /etc folder.

# rsync -zarvh root@173.***.***.72 /etc

Use 6: Display Synchronization progress in the Rsync command output

If you want to see the sync or copy progress in the Rsync command, use –progress:

# rsync -avh --progress root@ip_address:/opt/rpms_db /tmp

Use 7: Delete files at the 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 the Rsync command to delete the files on the destination using the –delete option; the example is shown below:

# rsync -avz --delete /opt/rpms_db root@ip_address:/tmp/rpms_db

Use 8: Put a limit on file transfer size

If you don’t want to transfer or copy the large files using Rsync, use the –max-size={specify-size-here} option. If we don’t want to transfer more than 1024 KB files, we can do this as per the below-given command.

Note: Use M for mb and G for GB.

#rsync -avz --max-size='500K' /opt/rpms_db root@ip_address:/tmp
Was this answer helpful? 0 Users Found This Useful (0 Votes)