As a system administrator or Linux power user, manually synchronizing directories or sharing files between computer systems can be extremely time-consuming. Sometimes if you lost connection while transferring files, you may require a tool that will resume the transfer process exactly where it left off once the connection is restored. Fortunately, there is an effective command line utility that will assist you in accomplishing this, which we will discuss in this guide.

Rsync Command

Rsync command is a powerful and flexible file copying utility. It can copy locally, to and from another host via any remote shell program, or to and from a remote rsync daemon.

It is well-known for its delta-transfer method using delta transfer algorithm, which lowers the amount of data transferred over the network by transferring only the differences  between the source and the already-existing files at the destination. Rsync command is a popular backup and mirroring tool, as well as an improved copy command for regular use.

In this guide, I'll provide step-by-step instructions on the usage of this tool and in-depth descriptions of the most popular rsync options.

Rsync syntax

Before we begin using the rsync command, let's go over the basic syntax.

The syntax for the rsync command in Linux is as follows:

Here is a breakdown of the Rsync syntax:

Rsync command Options

rsync provides a plethora of options for controlling every aspect of its behavior and allowing for the very broad specification of the list of files to be copied.

Some of the important rsync options are:

Option Description
-a, --archive Archive mode works similarly to the recursive mode (-r) , but it maintains all file permissions, file ownership, symbolic links and so on.
-z, --compress Used to  compress file data during the transfer.
-h, --human-readable Output numbers in a human-readable format
-b, --backup Make backups during file transfer
-n, --dry-run Instruct rsync to perform a trial run that does not make any changes. It is commonly used when deleting source files or in conjunction with the —verbose (-v) option to see what the rsync command will accomplish before running it.
-r, --recursive Instructs rsync to copy a directory and its subdirectories recursively.
--progress Show progress during transfer. This displays the amount of data transferred, the transfer speed, and the time left for the transfer to complete.
-e, --rsh This option lets you select a different remote shell program to use for synchronization between the local and remote copies of rsync. rsync is typically configured to use ssh by default, however on a local network, you may choose to use rsh as a remote shell.
-v, --verbose This option increases the amount of data logged by the rsync daemon during its initial phase.
-q, --quiet This option reduces the amount of data you receive during the transfer by suppressing information messages from the remote server. This option is useful when using cron to execute rsync.
--backup-dir When combined with the —backup option, this instructs rsync to store all backups on the receiving side in the specified directory. This is useful for incremental backups.
-u,--update Prevent overwriting destination files that have been modified.
--max-size instructs rsync not to transfer any files that are larger than the specified size
--min-size Instructs rsync not to transfer any files that are smaller than the specified size.
--remove-source-files Used to remove files  from the source directory.
--delete Remove unnecessary extra files files from the receiving side (files that don't exit from the source)
--port Instead of the default of 873, this specifies an alternate TCP port number for the daemon to listen on.
-i, --itemize-changes Check the difference between source files and destination files.
--bwlimit Limit the bandwidth used by rsync for efficient network utilization

How to Use Rsync

To use rsync, you must specify a source and a destination. The source or destination can be a remote system.