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 😉

You may also like...

4 Responses

  1. La_Tristesse says:

    Could you describe how to build csync for mac os x. I tried the linux tutorial from http://owncloud.org/dev/sync-clients/linux-build/ but I’m missing dependencies and don’t know how to get them.

    $ cmake -DCMAKE_BUILD_TYPE=Debug ..
    — The C compiler identification is GNU 4.2.1
    — Checking whether C compiler has -isysroot
    — Checking whether C compiler has -isysroot – yes
    — Checking whether C compiler supports OSX deployment target flag
    — Checking whether C compiler supports OSX deployment target flag – yes
    — Check for working C compiler: /usr/bin/gcc
    — Check for working C compiler: /usr/bin/gcc — works
    — Detecting C compiler ABI info
    — Detecting C compiler ABI info – done
    — Performing Test WITH_FPIC
    — Performing Test WITH_FPIC – Success
    — Performing Test WITH_STACK_PROTECTOR
    — Performing Test WITH_STACK_PROTECTOR – Success
    — Performing Test WITH_FORTIFY_SOURCE
    — Performing Test WITH_FORTIFY_SOURCE – Success
    CMake Error at /usr/local/Cellar/cmake/2.8.8/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:97 (MESSAGE):
    Could NOT find Log4C (missing: LOG4C_LIBRARIES LOG4C_INCLUDE_DIRS)
    Call Stack (most recent call first):
    /usr/local/Cellar/cmake/2.8.8/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:288 (_FPHSA_FAILURE_MESSAGE)
    cmake/Modules/FindLog4C.cmake:51 (find_package_handle_standard_args)
    CMakeLists.txt:39 (find_package)

  2. Linn Htoo says:

    Link to OwnCloud is wrong. I love csync and thank for all your hard work. 🙂

  1. Monday, April 2, 2012

    […] Andreas Schneider » Blog Archive » Synchronize two folders on a … […]

  2. Sunday, February 10, 2013

    […] usb e dischi rimovibili): csync. Naturalmente non ha interfaccia grafica, si usa da terminale. Qui qualche accenno all’uso di csync (in inglese). Non l’ho ancora testato, e spero di […]

Leave a Reply

Your email address will not be published. Required fields are marked *