How to synchronize files and folders on Linux

Linux administrators must keep folders synced on a regular basis. There are two simple use scenarios for synchronizing these files and folders. First, an important data backup needs to be maintained continuously at another location (local or remote). This backup runs at regular intervals. In other cases, the web server's data is copied to another server, for download sharing or for backup purposes. In both cases, there is a source point and a destination point needs to be synchronized.

Linux has powerful tools that allow users to synchronize files or folders from one source folder to another. However, the preferred tool for doing this is 'rsync'.

To do this, please follow these instructions:

Step 1 : Install the inotify tool

 sudo apt-get install inotify-tools 

Details can be found on github.com/rvoicilas/inotify-tools/wiki.

Step 2 : Install rsync

 sudo apt-get install ssh rsync 

Step 3 : Create a new bash script file named sync.sh

 nano sync.sh 

Step 4 : Paste the code below into 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 

The user must modify the destination directory and source in the shell command above to match his setup.

Step 5 : Execute the shell script file:

 chmod +x sync.sh 

Step 6 : Run the shell script:

 ./sync.sh 

Mission completed! At this point if any changes to the source directory are made, those changes will also apply to the destination directory.

Hope you are succesful.

See more:

  1. 7 commands to manipulate the most basic files and folders everyone must know
  2. Learn the file system and folders on Linux operating systems
  3. File Management in Unix / Linux
4.8 ★ | 5 Vote

May be interested

  • How to install Docker in LinuxPhoto of How to install Docker in Linux
    docker is a containerized utility that has become very popular, simplifying such tasks. moreover, when there is a problem with the operating system, instead of installing and reconfiguring the application, users only need to reinstall the operating system, copy the container again.
  • 5 best games on Ubuntu Snap StorePhoto of 5 best games on Ubuntu Snap Store
    users will find a lot of software in snap store, including a large number of interesting games. to help avoid trouble when searching, tipsmake.com has gathered some of the best games in the article below.
  • 20+ essential Linux security commandsPhoto of 20+ essential Linux security commands
    here are some of the most important security commands for everyday work on linux systems. if you're interested in security issues on your linux system, don't ignore these helpful security commands.
  • How to install Handbrake on LinuxPhoto of How to install Handbrake on Linux
    handbrake is a powerful open source tool for encoding and editing videos. it includes a graphical control panel to manage encryption and even preview the results.
  • The 5 most awaited things in Linux in 2019Photo of The 5 most awaited things in Linux in 2019
    linux has improved a lot in the past few years. some people who are not knowledgeable about technology have moved from windows to linux and responded very positively to this operating system.
  • How to create a burnable DVD copy on Linux with DevedeNGPhoto of How to create a burnable DVD copy on Linux with DevedeNG
    on linux, devedeng is a great way to create your own complete dvd video with interactive menus. devedeng allows users to easily combine their video files into a writable dvd image.