Trying to delete directory with "rm -rf", but get message that it's not empty

Reboot your computer and run rmdir(1) again.

$ rmdir -r empty_directory/

If that doesn't work, then try:

$ rm -rf empty_directory/

If it still doesn't work, assuming OS X has lsof(8) preinstalled, then enter:

$ lsof +D empty_directory/

This should tell if any files in this directory are being used by any programmes. I think that the HFS+ filesystem does not allow the deletion of files in use. Anyway, killall(1) any executables that might be using this directory or any hidden files inside it. It is likely that Finder is using a hidden file in the empty_directory directory to store folder view settings. Hope this helps.

P.S.: To find out if lsof(8) is installed, enter:

$ lsof

If the output looks like this, then lsof(8) is installed on your system.

lsof: /usr/bin/lsof /usr/bin/X11/lsof /usr/share/man/man8/lsof.8.gz

Check for any hidden and encrypted files or encryption key files in that directory. These could be the culprit.


Repairing the disk using Disk Utility fixed this problem for me.