Syntax
The syntax of writing and executing the rsync command is really simple.
In the above-given syntax, we first have to provide the options to the rsync command and later provide the source from where you want to transfer the data or files and destination path.
The most common options used in the rsync command are as follows:
-a option is for archive files and folders while synchronization,
-r is for synchronizing the files in recursive mode,
-v is for verbose output,
-b is for keeping the backup during the synchronization,
-z is for compressing and transfer the files,
-progress is for showing progress.
Installation of rsync command
Usually, the rsync command is already available in all Linux-based operating systems, but it does not come pre-installed in the minimal installation of an Operating system.
To install rsync in Ubuntu or any Debian based Operating system, use the command given below:
To install rsync in CentOS or RHEL based Operating system, use the command given below:
Rsync Command syntax for remote transfer
The syntax of the rsync command for remote transfer is a bit different. We have to provide the username and the IP address of the remote host where we want to transfer files using the syntax provided below:
Local to Remote Transfer
For transferring files from the local system to a remote system, you need to use the syntax given below:
Remote to Local
For transferring files from any remote host to the local system, you need to use the syntax given below:
Now, you have all the basic and required knowledge of the rsync command; let’s dig a bit more into the rsync command and understand what the rsync -avz command does.
What does the rsync -avz command do?
As we have discussed, some of the most useful options in the rsync command. The -avz options are used when we have to copy or transfer a directory and everything in it, subdirectories, and files.
The -avz options defines:
-a option is for archiving the files and subdirectories to preserve everything and then transfer using the recursion method.
-v option is for verbose output. By using this option, we can have more information about transfer instead of the silent transfer.
Z option compresses the whole data, reduces the file sizes, and transfers the data to the destination system. It comes in handy while transferring a huge amount of data over a slow internet connection.
So, collectively, using this combination of options(-avz), you will have the secure and quick file transfer due to the -a and -z options, while using the -v option, you will have a side-by-side a good amount of information about the transfer.
Let’s look at an example of the rsync avz command and have a clear understanding of it.
Example
Suppose we have a directory named Music, which includes a couple of mp3 files in it, and we want to transfer it to the Documents directory.
The command for transferring the Music directory would go like this:
After executing the above-given command, all the files and subdirectories inside the Music directory will be transferred securely and a little bit quickly using the rsync command; moreover, you will have verbose output.
Conclusion
Rsync is a command used for transferring files or directories from one place to another efficiently by just transferring the changes instead of the whole data again and again while back up or mirroring operations. This post provides the basic syntax, its usage, and installation method in any Linux-based Operating system. This post explained the in-depth knowledge about the rsync avz command and discussed it in detail and an example to have a clear and better understanding.