How to Sync Files and Folders on Linux?

Linux Sync Two Directories using rsync and inotify

Posted by Amritpal Singh on December 24, 2018

Linux has powerful tools that enables you to sync files or folders from one source directory to another destination directory. 

Step 1: Install inotify tools

sudo apt-get install inotify-tools

More information can be found on their wiki:

Step 2: Install rsync

sudo apt-get install ssh rsync

Step 3: Create a new bash script file called


Step 4: Paste the below code in the file

while inotifywait -r -e modify,create,delete,move /home/amrit/rsync-test/source_folder; do
    rsync -avz /home/amrit/rsync-test/source_folder /home/amrit/rsync-test/destination_folder --delete

You must modify the highlighted source and destination folder locations in the above shell script file to match your setup.

Step 5: Make the shell script executable

chmod +x

Step 6: Run the shell script


That's it, you are done! At this point if you make any change to the source directory, it will also apply to the destination directory.


Add Comment