In UNIX, directories are special (I feel myself channeling The Church Lady from SNL). Directories contain other files, so deleting them requires a different operation. Even when a directory is empty it still has two files in it (
..) so deleting a directory can't be done until it's really empty and the link counts on the relevant files have been updated.
In the early days of UNIX (my first experience is with 6th edition from Bell Labs) there were two different commands (
rmdir) for regular files and directories, which reflected the underlying fact that they were two different system calls.
rm was simple, it just removed the entry whose name you gave it from the directory, and decremented the ref count on the file it pointed to (of course, the file is not actually deleted unless the ref count goes to 0).
rmdir required much more (not actually in the app, but in the system call), it had to go into the directory and find the
.. entries, go to those inodes and decrement the ref count, and then remove the entry in the parent and decrement that ref count (the same one it just decremented for
. in the directory itself, which should then be 0). All of that straddled several different disk sectors, and so had to be carefully tuned to make the possibility of an abort (i.e. system crash) at any point be recoverable by fsck.
Of course, in more modern UNIX systems the constraints of the hardware (i.e. 64Kbyte max program size, that is a "K") have been eased and you can now do
rm -r and a lot of that underlying special nature of directories is less apparent, but it's still there. I remember needing to delete a large tree on the 6th edition machine which involved going into each directory, deleting all the files, going back to the parent and doing
rmdir and essentially doing all the recursion down all the directory trees manually. We did think about a script to help with this, but it came up so seldom in those days and it was sufficiently dangerous that we decided that requiring someone to go to all that effort would help prevent catastrophic mistakes.
The first time you get a question that says "I typed '
sudo rm -rf /' instead of
./ how do I recover?" you may understand why we were being cautious.