Search code examples
shellcommand-lineterminalcommand-prompt

Why am I getting "Directory not empty" error in terminal when using rmdir?


I am walking through a tutorial and it lets me delete two directories (I'm using one 10 deep, all empty) but once I try to remove the third it gives me that error message, even though there is no content in the directory and I am in the directory above it. Why is this? By the way I am using terminal.


Solution

  • That error is reported when the directory is not empty.

    To find out what files are in that directory use ls -a. The -a flag tells ls to list hidden files (aka "dot files"). Remove those files then rmdir can be used.

    Another option is to simply use rm -rf to recursively delete the directory and all of its files. NOTE: this can be dangerous if you give the wrong parameters - resulting in deleting more than you intended.