- It uses ssh or rsh for syncing files to or from a remote shell.
- TCP also helps rsync to sync files through the rsync daemon.
rsync installation:
If you do not have rsync on your system, utilize the below-given command for the rsync installation.
rsync is well-known for its delta algorithm deployment, allowing rsync only to copy the modifications made in the source files on the local host and the current files on the remote host.
rsync syntax:
- “Option” refers to rsync options.
- “Source” is for the source directory.
- “Destination” is for the destination directory.
Listing files using rsync
Method 1: rsync –list-only option
rsync, use the “–list-only” option for listing files instead of copying them. It does not identify the files that will transfer; it only identifies the candidates for being synced. This option is implied with a single source argument and no destination provided. The two primary usages of this option are as follows:
- Firstly, it is utilized for converting a copy command with its destination into a file-listing command.
- You can use –list-only option to specify the multiple sources.
Syntax of rsync –list-only option:
In the below-given example, we will utilize the rsync –list-only option to list the source directory “testdir2” on the remote host.
Method 2: rsync –files-from option:
The rsync –file-from option provides you the exact list of the files to transfer or sync. It modifies the default behavior of rsync and makes it easy to transfer only the specified directories and files. In addition, you can utilize the –file-from option for sorting out files list. This action allows rsync to work faster by avoiding revisiting the path elements that are common between the adjacent entries.
Syntax of rsync –files-from option:
Options:
- -a or archive mode: The -a option with –file-from prevents the -r option’s recursions.
- R or –relative option: The -R option maintains the information related to the specified path in the command.
- -d or –dirs option: It will force rsync to create directories specified in the list on the receiving end.
Now, let’s see an example demonstrating the –file-from option of the rsync command. Firstly, we will create a file list of the content present inside the “testdir1” directory. This rsync –file-from option will provide you a list of files that can transfer later.
Conclusion:
In Linux-based systems, rsync exists as a free software utility. It is used to sync or transfer directories and files from remote to the local system, local to a remote system, or the same system. For file transfer, sometimes, you need to check the files present in the source directory. This article provided you two methods for attaining the list of files present in the source directory, which includes “–file-from” and “–list-only” rsync options.