sammlinux sammlinux
  • Ubuntu
    UbuntuShow More
    How To Install and Use Docker CE on Ubuntu 22.04
    26 Min Read
    How To Install and Secure phpMyAdmin on Ubuntu 22.04
    5 Min Read
    How To Secure SSH with Fail2Ban on Ubuntu 22.04
    8 Min Read
    How To Install Uptime Kuma on Ubuntu 22.04
    17 Min Read
    How To Install Ubuntu Server 22.04 LTS with Screenshots
    14 Min Read
  • Rocky Linux
    Rocky LinuxShow More
    How To Install phpMyAdmin on Rocky Linux 9
    15 Min Read
    How To Secure SSH with Fail2Ban on Rocky Linux 9
    12 Min Read
    How To Install Rocky Linux 9.2 Server with Screenshots
    12 Min Read
    How To Set Up a Firewall Using FirewallD on Rocky Linux 9
    8 Min Read
    How To Install Nginx on Rocky Linux 9: A Comprehensive Guide
    10 Min Read
  • Debian
    DebianShow More
    How To Secure SSH with Fail2Ban on Debian 11
    8 Min Read
    How To Install Debian 11 (Bullseye) Server with Pictures
    12 Min Read
    How To Install and Setup Node.js on Debian 11
    6 Min Read
    How To Install PHP 8.2 on Debian 11
    12 Min Read
    How To Install Nginx on Debian 11: A Comprehensive Guide
    9 Min Read
  • Linux
    LinuxShow More
    Best Practices Linux Server Security for System Administrator
    8 Min Read
    A Simple Guide: How To Manage Groups on Linux
    5 Min Read
    How To Manage Log Files Using Logrotate In Linux
    7 Min Read
    The Easy Ways to Check File Size in Linux
    7 Min Read
    How To Backup Files From Remote Linux VPS Using Rsync Script
    12 Min Read
  • CentOS
    CentOSShow More
    How To Secure SSH with Fail2Ban on CentOS 7
    9 Min Read
    How To Install PHP 8.2 on CentOS 7 / RHEL 7
    18 Min Read
    How To Install Apache Web Server on CentOS 7
    11 Min Read
    How To Set Up a Firewall Using FirewallD on CentOS 7
    5 Min Read
    Initial Setup CentOS 7 Server: Secure and Efficient
    9 Min Read
  • DevOps
    DevOpsShow More
    How To Create AWS CloudFront: A Step-by-Step Guide
    10 Min Read
Reading: How To Use Rsync to Sync Local and Remote Directories in Linux
Share
Font ResizerAa
Linux for BeginnersLinux for Beginners
  • Ubuntu
  • Rocky Linux
  • Debian
  • Linux
  • CentOS
  • DevOps
Search
  • Ubuntu
  • Rocky Linux
  • Debian
  • Linux
  • CentOS
  • DevOps
Follow US
Copyright © 2014-2023 Ruby Theme Ltd. All Rights Reserved.

How To Use Rsync to Sync Local and Remote Directories in Linux

Samuel Siahaan
By Samuel Siahaan
Last updated: May 4, 2023
SHARE

Introduction

In the world of Linux, efficient data management is key, and Rsync stands out as a potent tool for synchronizing files and directories between local and remote systems seamlessly. This comprehensive guide will walk you through the process “How To Use Rsync to Sync Local and Remote Directories on your Linux system”. By the end of this guide, you’ll have a solid understanding of how to optimize your data synchronization workflow.

Contents
IntroductionTable of ContentsUnderstanding the Significance of Data SynchronizationPrerequisitesSetting Up Rsync on Your LinuxCentOS:Rocky LinuxDebian/UbuntuOpenSUSERsync Syntax for Directory SyncSyncing Local to RemoteSyncing Remote to LocalExclude Files or Directories in RsyncPreserve File Permissions and OwnershipAutomation Made Easy: Scheduling Sync Tasks with CronEnsuring Security in Data SynchronizationConclusion

Table of Contents

  • Introduction
  • Understanding the Significance of Data Synchronization
  • Prerequisites
  • Setting Up Rsync on Your Linux
    • CentOS:
    • Rocky Linux
    • Debian/Ubuntu
    • OpenSUSE
  • Rsync Syntax for Directory Sync
    • Syncing Local to Remote
    • Syncing Remote to Local
    • Exclude Files or Directories in Rsync
    • Preserve File Permissions and Ownership
    • Automation Made Easy: Scheduling Sync Tasks with Cron
    • Ensuring Security in Data Synchronization
  • Conclusion

Understanding the Significance of Data Synchronization

Effective data synchronization is vital in maintaining consistency across multiple systems. Whether you’re a developer collaborating on a project or a system administrator managing critical files, ensuring data is mirrored accurately between local and remote systems is imperative.

Prerequisites

In order to practice using rsync to sync files between a local and remote system, you will need two machines to act as your local computer and your remote machine, respectively. These two machines could be virtual private servers, virtual machines, containers, or personal computers as long as they’ve been properly configured.

If you plan to follow this guide using servers, it would be prudent to set them up with administrative users and to configure a firewall on each of them. To set up these servers, follow our guides :

- Advertisement -
  • Initial Setup Debian 11 Server: Secure and Efficient
  • Initial Setup Ubuntu Server 22.04: Secure and Efficient
  • Initial Setup Rocky Linux 9 Server: Secure and Efficient
  • Initial Setup CentOS 7 Server: Secure and Efficient

Setting Up Rsync on Your Linux

Before delving into using Rsync, ensure it’s available on your Linux distribution. The installation process varies:

CentOS:

sudo yum update
sudo yum install rsync

Rocky Linux

sudo dnf update
sudo dnf install rsync

Debian/Ubuntu

sudo apt update
sudo apt install rsync

OpenSUSE

sudo zypper update
sudo zypper install rsync

Rsync Syntax for Directory Sync

The fundamental syntax of Rsync is as follows:

rsync [optional] [source] [destination]
  • Options: These fine-tune the synchronization process.
  • Source: The directory or file you want to sync.
  • Destination: The target location for synchronization.

There are optional modifiers that function to determine the action of our command. A group of main options from rsync includes:

-rRecursive. Include directories and subdirectories as well as any files contained within the subdirectories.
-aArchive. The complete version from –r, where –a is an alias from group of options: -rlptgoD
Include the recursion option, preserves authorizations, file modification date/time, and group as well as user ownership.
-vVerbose. Displays a list of files that were copied during the sync process.
–deleteDelete, if the destination directory includes a folder or file which is missing from the source directory, delete it (can be done vice versa).
-zCompress the files that we will synchronize so that the file size can be much smaller. Rsync is smart enough to determine which file types need to be compressed or not
–excludeSpecify which file or folder patterns we want to exclude from the sync process.
–includeThe opposite of the –exclude option, it defines a pattern of file or directory names to include in the sync process. Usually, users combine the “option include” with the “option exclude”.
–dry-runOnly shows what process your command will do without actually doing it.
–progressIt displays the Kb transferred, and the Kb/s transfer rate.
Rsync Options (Rsync to Sync Local and Remote)

Syncing Local to Remote

To synchronize a local directory with a remote one, employ the following command structure:

rsync -avz /path/to/local/directory username@remote:/path/to/remote/directory

Replace “/path/to/local/directory” with the source directory on your local system. Replace “username” with your username on the remote system, and “remote:/path/to/remote/directory” with the destination directory on the remote system.

- Advertisement -

Syncing Remote to Local

Synchronizing a remote directory with a local one is similarly straightforward:

rsync -avz username@remote:/path/to/remote/directory /path/to/local/directory

Replace “username” with your username on the remote system, “remote:/path/to/remote/directory” with the source directory on the remote system, and “/path/to/local/directory” with the destination directory on your local system.

Exclude Files or Directories in Rsync

You can exclude specific files or directories from the synchronization process using the --exclude option. For example, to exclude a directory named “logs” from being synced, modify the command as follows:

- Advertisement -
rsync -avz --exclude 'logs/' /path/to/local/directory username@remote:/path/to/remote/directory

Preserve File Permissions and Ownership

If you want to preserve file permissions and ownership during the synchronization, you can add the --perms and --owner options to the command:

rsync -avz --perms --owner /path/to/local/directory username@remote:/path/to/remote/directory

Automation Made Easy: Scheduling Sync Tasks with Cron

Cron jobs let you automate Rsync synchronizations:

  • Open the terminal and type crontab -e.
  • Add a line with your desired schedule and Rsync command. For instance, syncing daily at midnight:
0 0 * * * rsync -avz /path/to/local/directory user@remote:/path/to/remote/directory

Ensuring Security in Data Synchronization

When dealing with remote systems, prioritize security. Utilize secure protocols like SSH for encrypted connections to maintain data integrity.

Conclusion

Using Rsync, you can easily sync local and remote directories, allowing for efficient file synchronization between different systems. By following the steps outlined in this guide, you can ensure that your files and directories remain up to date and consistent across multiple locations. Rsync’s versatility and flexibility make it a reliable choice for various synchronization tasks, including backups, data transfers, and mirroring. Experiment with different options and explore additional features of Rsync to tailor the synchronization process according to your specific requirements.

Also Read Our Other Guides :

  • How To Backup Files From Remote Linux VPS Using Rsync Script
  • How To Get Total Inodes and Increase Disk Inode Number in Linux
  • How To Create and Use Swap File on Linux System
  • How To Use Git Version Control on Linux: For Beginner
  • The 40 Most-Used Linux Commands You Should Know
  • 6 Methods To Search For Files By Name In Linux
  • How To Find Hard Disk Drive Information in Linux

Finally, now you have learned How To Use Rsync to Sync Local and Remote Directories in Linux.

TAGGED:LinuxRsyncSync

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
[mc4wp_form]
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share This Article
Facebook Copy Link Print
Previous Article How To Install and Configure NFS Server Client on Ubuntu 22.04
Next Article How To Install Docker CE on Centos 7
Leave a Comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

How To Install and Secure phpMyAdmin on Ubuntu 22.04
Ubuntu
Install and Configure Docker Swarm Mode on Centos 7
CentOS
How To Install and Config Thumbor on Debian 10
Debian
How To Install MariaDB 10.6 on Debian 11 Server
Debian
How To Install MongoDB 6.0 on Debian 10 & 11
Debian

You Might Also Like

Linux

How To Get Total Inodes and Increase Disk Inode Number in Linux

14 Min Read
Linux

How To Backup Files From Remote Linux VPS Using Rsync Script

12 Min Read
Linux

How To Create and Use Swap File on Linux System

9 Min Read
Linux

6 Methods To Search For Files By Name In Linux

7 Min Read
Linux

How To Install and Use Linux Screen with Commands

9 Min Read
Rocky Linux

Initial Setup Rocky Linux 9 Server: Secure and Efficient

18 Min Read
Linux

The Easy Ways to Check File Size in Linux

7 Min Read
Linux

How To Manage Log Files Using Logrotate In Linux

7 Min Read
Show More

Always Stay Up to Date

Subscribe to our newsletter to get our newest articles instantly!

sammlinux sammlinux

Providing beginner-friendly Linux tutorials and open-source guides to simplify your digital infrastructure.

www.sammlinux.com © 2026 | All Rights Reserved

Join Us!
Subscribe to our newsletter and never miss our latest news, podcasts etc.

Subscribe to our newsletter to get our newest articles instantly!

Zero spam, Unsubscribe at any time.
Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?