How to synchronize two folders in Bash?

Viewed 1027

I am writing a short script. One functionality is synchronizing two folders. Now I have two variables with directories to two different folder: DIRECTORY_1 and DIRECTORY_2. In both folders are files and other folders. I need to synchronize these folder to have all files in both folders. For example:

  1. In DIRECTORY_1 I have file1, file2, file3 and folder1
  2. In DIRECTORY_2 I have file4, file5, file6 and folder2

  3. I need comment after which I will have in both directories files1-6 and folders1-2.

I was trying rsync command but it doesn't work properly.

3 Answers

Use unison, it's a real folder synchroniser (such as Dropbox or Mega did).

https://www.cis.upenn.edu/~bcpierce/unison/

Mac installation with brew:

 brew install unison

I used this command:

unison -auto /path/folder1 /path/folder2

Moreover, and most important to me, if 2 files have the same name, it replaces with the most recent version.

Related