Rsync is a powerful synchronization tool that is written in C language. It works both for Unix and Windows systems. It is used for sync 2 paths as “source path” and “destination path“. Especially for huge number of files, it is very very useful tool to save your time and make your work easier.
Let’s try it out;
Note: It also can work between Windows and Linux machines. In this article, I will move on with Linux to Linux.
1.) Let’s create 2 folders such as src_path and dest_path
2.) Create empty .txt files into paths with touch command;
Into src_path, create 3 files => a.txt b.txt c.txt
Into dest_path, create 2 files => a.txt d.txt
Open a.txt into dest_path via vi text editor and write some words into a.txt file. Save and exit from vi.
3.) Now we have 2 different paths with different files and with different a.txt content like below;
4.) Open a terminal and run below command to sync 2 paths with rsync;
rsync -av --delete /home/ahmet/Desktop/rsync_test/src_path/ /home/ahmet/Desktop/rsync_test/dest_path/
Note: You can type rsync —help to see full meaning of arguments.
You will see below result;
5.) src_path and dest_path are successfuly synced to each other!
We can check a.txt in dest_path;
Yes! Into dest_path, a.txt became empty like in src_path because it is synced!
Also d.txt file is deleted because src_path does not have this file. ( —delete argument has provided it)
Thanks for reading 🙂