– A Simple Local Directory Synchronizer Script for Linux is a tiny and simple shell script used to synchronize two local directories: a source directory and a backup directory. It employs standard Linux/Unix tools such as find, sort, awk, mkdir, rmdir, cp and rm to support its underlying functionality.

Zaloha obtains information about the directories and files via the find command. Both directories must be available locally i.e mounted to the local file system. It also features reverse-synchronization, and can optionally compare files byte by byte. Besides, it asks users to confirm actions before they are executed.

In this article, you will learn how to install and use to synchronize two local directories in Linux.

Installing in Linux

To install, you need to clone its Github repository using the git command-line tool, but before that, you need to install git as shown.

# dnf  install git		# CentOS/RHEL 8/Fedora 22+
# yum install git		# CentOS/RHEL 7/Fedora
$ sudo apt install git		# Ubuntu/Debian

Once git is installed, run the following command to clone the remote repository to your system, move into the local repository, then install the script in a location in your PATH e.g /usr/bin and make it executable as shown.

$ git clone
$ cd
$ echo $PATH
$ sudo cp /usr/bin/
$ sudo chmod +x /usr/bin/
Install in Linux
Install in Linux

Synchronize Two Local Directories in Linux Using

Now that is installed in your PATH, you can run it normally like any other command. You can synchronize two local directories as shown.

$ sudo --sourceDir="./admin_portal/" --backupDir="/var/www/html/admin_portal/"

After running it, zaloha will analyze the two directories and prepares the commands necessary to synchronize the two directories.

Sync Two Local Directories in Linux
Sync Two Local Directories in Linux

You will be prompted to confirm the actions to be executed: “Execute above-listed copies to /var/www/html/admin_portal/? [Y/y=Yes, other=do nothing, and abort]:”. Answer yes to proceed.

File Synchronize Confirmation
File Synchronize Confirmation

Backup to External/Removable USB Media

You can also backup to a removable media (e.g /media/aaronk/EXT) mounted to the local file system. The destination directory must exist for the command to work, otherwise you will get the error message “ <backupDir> is not a directory”.

$ sudo mkdir /media/aaronk/EXT/admin_portal
$ sudo --sourceDir="./admin_portal/" --backupDir="/media/aaronk/EXT/admin_portal"
Backup Files to USB Device
Backup Files to USB Device

Backup Changes from Source to Backup Directory

Now make more changes in the source directory, then run once more to back up the changes in the external disk as shown.

$ mkdir /home/aaronk/admin_portal/plugins
$ mkdir /home/aaronk/admin_portal/images
$ sudo --sourceDir="/home/aaronk/admin_portal/" --backupDir="/media/aaronk/EXT/admin_portal" will create the new directories in the backup directory and copy any new files from the source as well as highlighted in the following screenshot.

Sync New Changes in Linux
Sync New Changes in Linux

Reverse Synchronize Changes from Backup to Source Directory

Assuming you have made changes in the backup directory to files that already exist in the source directory, you can make the changes reflect in the source directory using the reverse sync feature, enabled using the --renUp option.

$ --revUp --sourceDir="/home/aaronk/admin_portal/" --backupDir="/media/aaronk/EXT/admin_portal"
Reverse Sync from Backup to Source
Reverse Sync from Backup to Source

Note that any new files or directories created in the backup directory that doesn’t exist in the source directory will also be deleted as indicated in the following screenshot.

Reverse Synchronize Files
Reverse Synchronize Files

You can tell zaloha to follow symbolic links on the source directory using the --followSLinksS option and on the backup directory using the --followSLinksB option.

$ sudo --followSLinksS  --followSLinksB --sourceDir="./admin_portal/" --backupDir="/var/www/html/admin_portal/"

To view the Zaloha documentation, run the following command.

$ --help

That’s all for now! is a small and simple Bash-based backup script to synchronize two local directories in Linux. Give it a try and share your thoughts with us via the feedback form below.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

10 thoughts on “ – A Simple Local Directory Synchronizer Script for Linux”

  1. Aaron,

    You seem to have had problems with getting REV.NEW to work: The option --revNew must be given and the file to be REV.NEW-ed must be younger than the last run of (= implies that it was created directly in the backup directory).

    If the file is older, then it will be REMOVE-ed, as this implies that it must have existed in the source directory before and somebody removed it from the source directory …

  2. Add rsync comparison: Clearly Rsync is a program with 20 years history, a de-facto standard, more feature-rich, network-capable and its delta-transfer algorithm has been a landmark in IT. However, this program has the following strong points (besides being very small):

    1) It has the interactivity (execute only after user’s confirmation) plus finer information about the actions. E.g. write of a new file is NEW and the update of an existing file is UPDATE. If you use the --color option, NEW will display black/white (less risky operation) and UPDATE will display red (overwriting = more risky operation = more attention needed). I am not aware that rsync would give you that level of detail.

    2) rsync is memory-constrained as it builds its file lists in memory. Problems have been reported with huge directory trees. This script builds and processes its file lists as CSV files (= not memory-constrained).

    3) it has been reported that Rsync is slower than cp when acting locally. This is caused by the fact that rsync has a checksum-computing function built-in that is active even when copying locally. This program invokes the operating system’s cp command directly.

    4) integrations with other systems, needed changes, etc: a shell script has certain advantages over a binary program

  3. What does this script offer better than the infinitely more mature rsync? Rsync works for any combination of local and remote sources and backups as well.


Got something to say? Join the discussion.

This site uses Akismet to reduce spam. Learn how your comment data is processed.