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:
- 7 commands to manipulate the most basic files and folders everyone must know
- Learn the file system and folders on Linux operating systems
- File Management in Unix / Linux
You should read it
- 14 interesting Linux commands in Terminal
- Basic Linux commands everyone needs to know
- How to manage photos on Linux
- 5 Linux commands every sysadmin needs to know
- Guide to network operation for Linux users: 11 commands to know
- Convert data, applications from Windows to Linux in minutes
- How to Run Linux Commands on Windows with WSL 2
- Manage folders in Unix / Linux
May be interested
- How to interact with files and contacts in Gomastering how to use the file system with the useful functions below will greatly help your work. here's how to interact with files and folders in go .
- How to create and delete folders in Linux Terminalfolders are essential for your linux operating system because they contain files you may use often or that the system needs to function correctly.
- How to delete files and folders on Dropboxafter a long time using dropbox leads to more and more storage space on dropbox. you should clean up dropbox, delete files or folders that are no longer in use.
- Instructions for setting password to protect files and folders in Windowshow to protect folders and data on computers? how to set a password for a folder, is it difficult? take a look at the answers in our windows directory and encryption tutorial.
- Synchronize cloud storage services on Linux with Rclonerclone has the same function as rsync but can be used for many cloud storage. it is a terminal-based utility that synchronizes folders and files on local systems and on other cloud storage services.
- How to use wildcards to match file names in Linuxsearching for files in linux can seem confusing at first, but don't worry, it gets easier once you understand wildcards. wildcards are special symbols that help you select multiple files or folders without having to type each name individually.
- How to compress and decompress files and folders on a Macon the mac, there is a built-in tool to compress and decompress files and folders that users do not need to install the application, if only the basic compression and decompression features.
- How to hide files and folders on Windows / Linux / Mac OS X operating systemshiding a file / folder simply means that a normal file / folder is set to 'hidden'. a few tricks to help you keep data confidential.
- How to access Linux files on Windows 10windows 10, april 2019 update brings a long-awaited feature: support for easy access, viewing and even modification of windows subsystem for linux files (wsl) from file explorer or via stream command.
- Synchronize files and folders on Desktop and Document on macOS Sierra with iCloudone of the great features on macos sierra is the ability to use icloud drive better by syncing the files and folders found on the desktop and in the documents folder.