Linux Sync Two Directories using rsync and inotify

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/user/rsync-test/source_folder; do
    rsync -avz /home/user/rsync-test/source_folder/home/user/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.

Post a Comment

Previous Post Next Post