Server Fault is a question and answer site for system and network administrators. 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

I use rsync v. 3.0.4 and when I need to move something I use it with the --remove-source-files. I prefer rsync than mv.

Unfortunately, when I use --remove-source-files, the directories are left on the source side (as said in the man). Is there a way to remove directories too once moved all the files?

share|improve this question
It might make sense to file a ticket with the rsync developers. An option to remove the directories as well would be a nice thing to have. – user161233 Feb 22 '13 at 0:25
up vote 4 down vote accepted

You could always delete them manually with something like this:

find /path/to/directory -depth -type d -print0 \
    | xargs --null --no-run-if-empty rmdir --

This will only delete empty directories.

share|improve this answer
good idea. Thanks! – damko Dec 19 '09 at 22:29
A much more elegant solution with current find versions would be: find /path/to/directory -type d -empty -delete – Michael Renner Apr 3 '11 at 2:04

You might be able to get rsync to write a log file in a format that your script could parse for the names of the directories to delete. See man rsyncd.conf for the available log format escapes.

share|improve this answer

Can't you just "rm -rf" them?

share|improve this answer
yes of course, that's what I do. But in an automated process (a script) I would like it's the program doing that, otherwise I have to launch a script after that and I have to make checks on not-empty directories before deleting them. Not impossible to do but I'm looking for something ready to go. – damko Dec 19 '09 at 14:15

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.