Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I set up an instant file sync for two local directories? The catch is I need it in real time (15, 10 or even 5 seconds is too slow), and I don't want the target root directory created.

For example, something similar to...

cp -fr sourcea/* /some/destdir
cp -fr sourceb/* /some/destdir
cp -fr sourcec/* /some/destdir

Catching deletions would be nice too, though it's not a deal breaker.

I do not want the "sourcex" created within destdir. (hence the *). I've tried using rsync, which apparently wasn't close or even close to real-time, as well as several generic sync systems. However, most will want a 1 to 1 sync, rather than contents only.

Any suggestions? I've been fighting this for a while now, so any help would be greatly appreciated!

share|improve this question
up vote 7 down vote accepted

A filesystem overlay would probably work better for this. Using something like aufs you can create a 'virtual' directory out of several combined directories. You can configure whether writes should propagate back to the original directories, or use a copy-on-write method to leave the originals alone, or disallow writes altogether.

However to answer your original question, you can use something like lsyncd to trigger an rsync as soon as a file is modified. lsyncd uses rsync, which is capable of syncing directory contents without keeping the directory name. Generally the way to do this is to sync sourcea/. to /some/destdir/. The important part is the dot at the end of the source path. This is a general trick that can be used for things other than rsync, like cp.

share|improve this answer
Thanks! This actually works a lot better for me. – Adrian Schneider Feb 17 '12 at 17:49

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.