Rsync is a command-line utility used to sync your files and folders within both a local environment and to any remote desktops you'd like to sync to as well. It is also useful for performing backups to your data in case of system failures. Another tool that is also used for file transfer between desktops is SCP (Secure Copy). The difference, however, is that when updating files, Rsync updates only the changed bits/data of files while SCP uploads the whole file again regardless of whether there are changes or not. Naturally, this means that Rsync is much more time-efficient. Rsync is also more bandwidth-efficient as it uses compression and decompression when transferring files, reducing the data needed to reconstruct the file once it is transferred.
Options
Rsync has options that will often be used in tandem. They are the following:
-r ; copies data recursively (allows you to transfer whole directories including directories within those directories)
-z : compresses the file data
-e : specifies a transfer protocol
Using Rsync Locally
When we refer to using Rsync "locally", we mean using it to manage the transfer of files in the local desktop from one file location to another. Note that this process is very similar to using the cp command.
Using Rsync to transfer Directories to and from remote directories
In order to sync directories from a local directory to a remote directory, we can input a command following the template:
rsync -rz /local/directory [email protected]:/some/directory
A similar template is used when syncing from a remote directory to a local directory:
rsync -rz [email protected]:/some/directory ~/some/directory
Using Rsync with the SSH Protocol
You also have the option of using the SSH protocol with syncing so that you can encrypt your files while transferring. This can be done by using the -e option like so:
rsync -e ssh ~/some/file.txt [email protected]:~/some/directory
Similarly, you can transfer files from a remote directory to a local directory with similar syntax:
rsync -e ssh [email protected]:~/some/file.txt ~/some/directory
Some Other Options
Rsync also has some other options that you might find useful:
--remove-source-files; deletes the file from the source location
--max-size ; only transfers files under the specified size
--delete; deletes files in the destination directory if they don't exist in the source directory
That's all for this short tutorial. We can see that Rsync offers more versatility than SCP, however SCP can be used to accomplish the same thing. If one isn't working, try the other!