Super User is a question and answer site for computer enthusiasts and power users. 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'm new to UNIX (MAC OS X bourne shell POSIX), I understand rmdir will only remove an empty directory but under what circumstances would you actually want to use rmdir <directory name> and not just rm -r <directory name>? Is there an intelligent use case I'm failing to appreciate and that knowing about would make my programming that little bit better if I did? Thanks.

share|improve this question

migrated from Sep 22 '12 at 21:51

This question came from our site for professional and enthusiast programmers.

up vote 5 down vote accepted

rmdir is safer: it refuses to remove a directory if it contains any files. What if you are trying to remove the wrong directory, or the directory still contains (possibly hidden) files you need?

There are also historical reasons: in the beginning the rm program didn't have a -r switch, so rmdir was needed to remove directories. Back then rmdir was a non-trivial program but today it is just a wrapper for the rmdir(const char*) C function.

share|improve this answer

I use rmdir when I'm removing a directory that I expect to be empty, so that it will fail if there are still files in it. Using rm -rf might blow away files that I want to keep, if I mistype something.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .