Synchronize two folders on a Mac and other Unix Systems with csync

I’ll show you how to to synchronise files of two different directories in a terminal using a mighty automator. The tool is called csync and is a client side file synchronizer. Unless like rsync it syncs in two directions so that the contents are equal as soon as it finished.

Here is the simple example of syncing two folders from terminal:

csync /path/to/folder1 /path/to/folder2

If you run it the first time, this line compares the both directories and copies the files missing in each other directory to the opposite side. So in the end they are equal. If you delete a file in folder1 it and run it again, csync will notice that the file has been deleted in folder1 and will delete it in folder2. If you create a new file in folder2 and run csync, it will copy the new file to folder2. If a file has changed it will detect it and copy the file to the other folder. If a file has been changed on both sides, the newer file wins.

The options are pretty simple and don’t need further documentation here. The only interesting option is an additional exclude list. The default one can be found in ‘~/.csync/csync_exclude.conf’.

You can always check the manual of Rsync by typing “man csync” in terminal.

The current stable version supports the SMB (Windows sharing) protocol and SFTP.

If you want to synchronize a local folder with a folder on another unix machine you can use the following command:

csync /path/to/my/music/collection sftp://my.notebook/home/me/my/music/collection

and it will do the same as stated above, but over a sftp network connection. SFTP is the file transfer protocol which is based on SSH and every Unix machine has it normally enabled by default.

We are currently improving csync and adding support for OwnCloud. A graphical Qt based frontend for csync is mirall.

This post is inspired by this one 😉