How to use Rsync on Linux: Top Practical Examples


Rsync is a Linux-based tool that can be used to sync files between remote and local servers. Rsync has many options that can help you define the connections you make. From deciding the type of shell that should be used to files that should be excluded in a transfer, Rsync gives you the power to shape the transfer specifications.

  • The advantage of incremental backup may be used, supports the socket, several (sliding supports are client-reference)
  • The remote fellow shell can also encrypt (ssh) transmission, socket, you require encrypted transmission, or the service may be utilized ××× ipsec service.
  • Rsync uses compression and decompression methods while sending and receiving data at both ends, leading to less bandwidth consumption.
  • Rsync has the support for copying devices, groups, links, owners, and permissions.

In the following tutorial, you will see some standard methods on how to use rsync on Linux with command examples, along with how to install the software on various Linux systems.

Install Rsync On Linux

Below are some of the most common Linux systems and how to install Rsync.

Install Rsync Arch Linux-based distributions

sudo pacman -Sy rsync

Install Rsync Fedora and RHEL-based distributions

sudo yum install rsync

Install Rsync Debian and Ubuntu-based distributions

sudo apt install rsync

Install Rsync openSUSE-based distributions

sudo zypper install rsync

Rsync Command Syntax

First, knowing the basics of Rsync syntax is helpful, which is straightforward and operates in a similar CP, SCP, and SSH operation style. Some examples are as follows:

FunctionSyntax Example
Local Sync:rsync {options} {Source} {Destination}
Remote Sync Pull:rsync {options}  <User_Name>@<Remote-Host>:<Source-File-Dir>  <Destination>
Remote Sync Push:rsync  <Options>  <Source-Files-Dir>   <User_Name>@<Remote-Host>:<Destination>
  • DEST – Destination directory.
  • HOST – Remote hostname or IP Address.
  • OPTION – The rsync options.
  • SRC – Source directory.
  • USER – Remote username.

Rsync Commands

Rsync comes with a significant number of options to control how to apply and use the sync software. Some of the most common commands are below:


-a, –archivearchive files and directory while synchronizing ( -a equal to following options -rlptgoD)
-b, –backup take the backup during synchronization
-l, –linkscopy symlinks as symlinks during the sync
-d, –deletedeletes extraneous files from the destination location.
-e, –rsh=COMMANDmention the remote shell to use in rsync
-h, –human-readable display the output numbers in a human-readable format
-u, –update   don’t copy the files from source to destination if the destination files are newer
-r, –recursive     sync files and directories recursively
-n, –dry-run   perform a trial run without synchronization
–p, –progressshow the sync progress during the transfer
-z, –compress   compress file data during the transfer
-q, –quiet   suppress message output
-v, –verbose  verbose output

Copy/Sync Files and Directory Locally

The following command will sync a single file on a local machine from one location to another location. The example will take the following file ( and copy or sync it to the (/tmp/backups/) folder.

rsync -zvh /tmp/backups/

Note that the Rsync command can create a directory even if the path does not exist.


Copy/Sync a Directory on a Local Computer

To transfer or sync all the files from one directory to a different directory on the same machine. The example you will see here is taking the (downloads) directory and creating a backup in sync location (/tmp/backups/).

rsync -avzh /home/joshua/Downloads /tmp/backups/

Copy a Directory from a Local Server to a Remote Server

Rsync can sync directories to and from local servers to remote servers. In the following example, we will use the folder (backup) on your local server to be sent to remote machines in your internal or external network.

rsync -avz backup/ root@

Copy/Sync a Remote Directory to a Local Machine

The next Rsync remote directory example will sync the opposite way. The following example code snippet will use Rsync to sync a remote directory to your local server. Example directory (/home/josh/backup/packages) to be copied to your local server (/tmp/packages).

rsync -avzh root@ /tmp/packages

Copy a File from a Remote Server to a Local Server with SSH

One of the most popular ways to transfer data between local and remote servers is to use SSH (Secure Shell) as the data is protected in a secured connection and encrypted so that nobody can read the data in transit which, given the privacy concerns, these days, is a critical factor.


To specify a protocol with rsync with SSH, you need to specify the (-e) protocol option as per the start of the guide with basic commands and syntax.

rsync -avzhe ssh root@ /tmp/

Copy a File from a Local Server to a Remote Server with SSH

The following example will show the opposite with rsync syncing a file, this time from your local server to a remote internal or external server using SSH and Rsync.

rsync -avzhe ssh root@

Exclude Files and Directories

These two options allow you to exclude files by specifying parameters. The first option is to use the (–exclude) argument and specify the files and directories you want to exclude on the command line.

Firstly, when excluding files or directories, you need to make sure that you use the relative paths to the source destination, or else it will fail or have incorrect outcomes in excluding the wrong files. In the following first example, you will see an option to exclude (cache) and (tmp) directories:

rsync -a --exclude=cache --exclude=tmp /src_directory/ /dst_directory/

In the second option, you will use the (–exclude-from) option and specify the files and directories you want to exclude which are stored in a file.

rsync -a --exclude-from='/exclude-file.txt' /src_directory/ /dst_directory/

Set the Max Size of Files to be Transferred

The following example will limit the size of files to be synced. This is useful for constantly running rsync between local and remote machines where files possibly could bloat or bandwidth factors come into play.


rsync -avzhe ssh --max-size='100k' /var/log root@

Note that you must specify the size. For example, KB uses K, MB uses M, and GB uses G.

Show Progress While Transferring Data with Rsync

Another popular feature when syncing large directories is to see the progress. This can be done in the following example using the (-progress) option, which will show the files and the time remaining on completing the transfer.

rsync -avzhe ssh --progress root@

Do not Sync/Copy Modified files from the Destination

Sometimes you may require the source to not sync and copy any changes from the destination. An example of this would be backing up all files to a backup server, and you want only the source to sync and ignore any changes at the destination since they will not be valid on your source server to avoid corruption.

This can be done using the -u flag in the rsync command.

rsync -avzu root@ /backup/website1

Comments and Conclusion

Rsync is probably one of the most efficient, accessible, and secure ways to sync files between operating systems and servers. One drawback is that rsync can accidentally overwrite your files, so it is vital to double-check everything before you sync or use the (–dry-run) option.

Rsync is fantastic for moving complex file syncs and for transferring a large number of files. To many users, it’s better to use Rsync for moving large batches of files than SCP. When used with cron, Rsync is also able to take automatic backups. While it may look and sound difficult, Rsync can be beneficial and accomplish things that less intimidating interfaces may not be able to.


Share on: