Linux has powerful tools that enables you to sync files or folders from one source directory to another destination directory.
1. Install inotify tools
sudo apt-get install inotify-tools
More information can be found on their wiki: https://github.com/rvoicilas/inotify-tools/wiki
2. Install rsync
sudo apt-get install ssh rsync
3. Create a new bash script file called sync.sh
nano sync.sh
4. Paste the below code in the sync.sh file
#!/bin/sh
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
done
You must modify the highlighted source and destination folder locations in the above shell script file to match your setup.
5. Make the shell script executable
chmod +x sync.sh
6. Run the shell script
./sync.sh
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.