I've always been curious why the command for deleting everything in a directory is
Why aren't there flags to do the same thing with
Wouldn't it be more intuitive to use
rmdir for directory operations?
In the early Unix File System (at least back in the V7 days circa 1970) directories were implemented as special files and only root could use the
mknod(2) system call that created them and only root could
unlink(2) a directory special file.
These protections were in place in order to keep the filesystem structure consistent. For example, if a user was allowed to write to a directory special file, he could make its parent directory
.. point to itself (specifically its own i-node). This would create a circular reference in the filesystem which would be a Bad Thing. Of course there are other inconsistencies one could make, this is just a clear example.
The consistency was maintained by user-space programs like
rmdir(1) which were Set-UID root so that they could make the privileged system calls on behalf of an unprivileged user. When recursion was added to
rm(1), the remove command would run as the current UID and then call out to
rmdir(1) solely for removing empty directories. This is still a pretty standard method of elevation of permission: don't use more permissions than you need.
rmdir(2) were added as their own system calls but the relation between
Personally, I find it a tad more satisfying to
rmdir junk and know that the worst I did was remove an empty directory.
rm was made to remove the references to files,
rmdir was made to remove directories, parallel to
mkdir. Many years ago, Unix
rm could only remove directories by invoking
rmdir. There also wasn't an
rmdir(2) system call,
rmdir was a program that called
Purely a matter of opinion, but
rm removes files while
rmdir removes directories. A directory is a file, but a special type of file, so it makes sense for
rm to remove them, but to treat them specially (i.e. to require an extra option to enable the capability.) On the other hand not all files are directories, and it makes no sense IMHO for
rmdir to remove something that isn't a directory.