The Linux Page

rsync: delete_file: rmdir "<path>" failed: Directory not empty

I have different scripts that synchronize different hard drives for either backup or just synch-ing my development system with one of the production systems.

I got an error for a little while after I created a folder on a destination as I wanted to make sure that the source folder was being copied...

That generated an error as follow:

  rsync: delete_file: rmdir "<destination>" failed: Directory not empty (39)
  rsync error: some files could not be transferred (code 23) at main.c(977) [sender=2.6.9]

The fact is that the source file was a softlink and not a folder. So the folder was being copied anyway, but this softlink could not be copied because the destination was a non-empty folder.

So rsync attempts to copy the softlink in this way1:

  if test -d <destination>; then
    rmdir <destination>
    if test -e <destination>; then
      echo error: some files could not be transferred...
    else
      ln -s <some place> <destination>
    fi
  if

Obviously, the message is not crystal clear since it says it will transfer a file when the error is about not being able to remove a folder. I think there ought to be an exception for this special case.

  • 1. Of course, rsync is written in C but this shell script still shows the algorithm.