“RSYNC stands for remote synchronization, and it is a multi-purpose tool that is mainly used for transferring data from one location to another. Moreover, it is also used for data synchronization between different storage locations. These storage spaces can either be remote or local, i.e., you can even use this tool for synchronizing and transferring data to a remote location. In this article, we will discuss some of the options associated with this tool along with a few helpful examples to demonstrate its usage.”
RSYNC Command Options
The RSYNC command in Linux offers different options that can be paired up with this command to produce the desired results. To learn about all these options, all you need to do is to run the command shown below:
$ rsync --help
All the options of the RSYNC command, along with their detailed description, are stated in the help manual of this command, as shown in the following image:
The most commonly used options of the RSYNC command are discussed below:
- -a: This option is used for copying files recursively while preserving all the symbolic links, file permissions, timestamps, etc. It is known as the archive mode.
- -v: This option is used for displaying the details about the data being transferred during the execution of the RSYNC command. Moreover, it also displays a summary of the whole transaction at the end of the execution. This option stands for verbose.
- -h: This option is simply used for displaying the output of the RSYNC command in the human-readable format.
- –progress: This option is used for displaying the progress of the ongoing data transfer.
We will be using all of the options discussed above in the examples that we have designed for you.
RSYNC Command Examples
We have implemented the following three examples to show you the basic usage of the RSYNC command:
Note: The usage of the RSYNC command is not only restricted to these examples; rather, it can be used to serve many other purposes.
Example # 1: Using the RSYNC Command for Listing the Contents of a Directory
In this example, we want to use the RSYNC command for listing the contents of a directory. For that, we will use the RSYNC command in the manner shown below:
$ rsync /home/system/Temp1/
Whenever we use the RSYNC command along with a directory without specifying any other options, then it works just like the “ls –l” command and displays the contents of the specified directory. In this particular example, we wanted to display the contents of the “Temp1” directory. The contents of this directory are shown in the following image. This output not only presents the contents of the said directory but also specifies the access permissions of this directory as well as all of the files and sub-directories.
In the same manner, you can use this command to display the contents of any directory of your system simply by replacing “/home/system/Temp1/” with the exact path of your particular directory.
Example # 2: Using the RSYNC Command for Copying the Contents of a Directory to Another
Now, we will use the RSYNC command for copying the contents of one directory to another. For that, we will use the RSYNC command in the manner shown below:
$ rsync –avh /home/system/Temp1/ /home/system/Temp2/
This command will simply copy all the contents of the “Temp1” directory to the “Temp2” directory. The “avh” options will display the output in human-readable format along with all the relevant information. The output of this command is shown in the following image:
To confirm if the contents of the directory “Temp1” have been successfully copied to the directory “Temp2”, we will display the contents of the “Temp2” directory by running the command shown below:
$ rsync /home/system/Temp2/
The following output shows that all the contents of the directory “Temp1” have been successfully copied to the directory “Temp2”.
Similarly, you can use this command to copy the contents of your desired source directory to a destination directory of your choice simply by providing the correct paths for the source and the destination.
Example # 3: Using the RSYNC Command for Displaying the Copying Progress
Finally, we will use the RSYNC command to display the progress while copying the contents from one directory to another. For that, you simply need to run the command shown below:
$ rsync –avh --progress /home/system/Temp1/ /home/system/Temp2/
The “progress” option is used for displaying the copying progress as shown in the following image:
This option is particularly useful in situations where you are copying large files from one location to another that take up a reasonably long time.
Conclusion
In this guide, we discussed some of the useful options of the RSYNC command along with a few examples that elaborated on the usage of this command. After going through this guide, you will be able to use this tool very efficiently for transferring data from one location to another.