Back to blog
GuidesSeptember 7, 2026·4 min read

How to Use rsync on Linux to Sync Local & Remote Directories

How to Use rsync on Linux to Sync Local & Remote Directories

Folder-to-Folder Transfer with Rsync and other operations

Basic command for folder-to-folder transfer

rsync -a source/ destination/

-a is the archive mode flag that starts most of rsync commands. Archive mode makes rsync recursively traverse subdirectories, preserving permissions, timestamps, ownership, and symlinks during transfer. It works equally well whether the destination is another directory on the same disk or the mount point on a distant machine.

It is critical whether there is a trailing slash at the end of the source: source/ copies the contents of the directory, while source (without slash) copies the directory as a subdirectory inside the destination directory. It is a small difference, but it makes very different results. Read the full explanation in our guide to rsync's recursive copy behavior.

Syncing to the remote server (push)

Providing the destination as user@host:path makes rsync send the files over the network instead of transferring files locally:

rsync -a source/ user@host:/remote/path/

All rules of the local syntax apply, including the archive mode and the trailing-slash rule. The only difference is the destination location.

Syncing from the remote server (pull)

To get the files from the remote location, just swap the positions in the command:

rsync -a user@host:/remote/path/ destination/

It is the same command with the remote side as the first parameter. It can be used for getting backup on the local machine or the configuration directory from the server meant to be decommissioned.

Using non-standard SSH port or key

By default, rsync uses SSH as its remote shell on modern systems; hence, a regular user@host:path automatically uses SSH without extra flags. In case if the remote side uses non-standard port number or needs a particular key, they can be passed to rsync through the -e option:

rsync -a -e "ssh -p 2222 -i ~/.ssh/deploy_key" source/ user@host:/remote/path/

-e accepts any SSH command line. The port number, the identity file, and other SSH options can be passed to ssh inside those quotes.

Data compression over the network

rsync -az source/ user@host:/remote/path/

-z option compresses the data before sending, which is helpful in case of the slow or low-bandwidth connection. In case of local copies or high-speed LAN transfer, the CPU overhead introduced by the compression will not be beneficial since it is not the network bottleneck. Use -z for the network transfer and skip it in case of transfers on the same machine or local network.

Showing progress bar and resuming interrupted transfers

rsync -aP source/ user@host:/remote/path/

-P option combines --progress and --partial. --progress shows the progress bar for each file, instead of doing nothing in the terminal. --partial keeps the partial files in case of an interruption, making it possible to restart the transfer without starting from scratch. This combination is especially useful for large transfers on unstable connections.

Creating the exact mirror of the destination

By default, rsync preserves the existing data at the destination by updating or adding files, but it does not delete the unnecessary files at the destination. For creating the real mirror, the --delete option is required:

rsync -a --delete source/ user@host:/remote/path/

This operation is destructive in essence: all destination files that are not in the source are deleted. It is reasonable to do a dry run before performing the operation:

rsync -a --delete --dry-run source/ user@host:/remote/path/

It is recommended to check the generated list of files and disable --dry-run only after checking.

Symlinks, briefly

In the archive mode, rsync copies the symlinks as symlinks, instead of copying the files the symlinks point to. In case if you want to copy the target of the symlinks (for example, moving a directory to the server where the original targets of symlinks do not exist), use -L to follow the symlinks. Read our dedicated rsync recursive-copy guide for the full breakdown of symlink handling.

About bidirectional synchronization

All commands listed perform unidirectional transfers per each execution—either from source to destination or from destination to source. Rsync does not sync both sides together like a bidirectional sync tool should do. In case of the need of bidirectional sync, you can consider using alternative tools like Unison or a version-control based workflow. In practice, synchronizing two machines using rsync means scheduling or executing transfers in one of two directions depending on what changes are needed.

For regular syncing between the local machine and a server, OrbitServers VPS and bare-metal instances provide full root access and SSH right from the first login. All commands mentioned above can be executed without additional configuration.

Get started with Orbit Servers

Low-latency VPS, bare metal, and colocation across the US, EU, and APAC - provisioned instantly and built for performance-critical workloads.

Get started
J

Written by

Julius

Related posts