Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 stackoverflow.com Sep 22 '12 at 21:51

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

2 Answers 2

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

Your Answer

 
discard

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.