Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

I'm trying to use rsync to keep to folders in sync. Let's call them SRC and DST. When I delete a file in SRC and I run my rsync command, I want the corresponding file in to be deleted. When I delete a directory in SRC, I want all corresponding files to be deleted in DST but to keep the empty directory structure.

Is it possible ?

share|improve this question

Perhaps you could do it, doing first a find in your SRC, and looking for empty directories, putting this directories in an exclude file and then passing this exclude file to rsync. Then it could work.

To find your empty dirs do

find SRC -type d -empty > SRC-empty-dirs.dat

Do alter

rsync --exclude-from=SRC-empty-dirs.dat SRC DEST

to exclude from a file.

BUT I didn't test this myself.

share|improve this answer
I would consider that as cheating ;-) – Guillaume Mar 15 '11 at 11:18

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.