Given rm why does rmdir exist?
Is there any resultant difference on disk between using rm or rmdir to remove a directory?
Or is it only different by usage preference, By example, given
$ mkdir a
$ mkdir a/b
$ mkdir a/b/c
Would
$ rmdir -p a/b/c
have the same effect as
$ rm -r a
just looking at it from a different end?
rmdir
will only remove empty directories while rm -r
will remove directories and files within them recursively. Thus, it is safer to use rmdir.
It can save one when hidden files get involved since a cp *
or mv *
won't copy or move the hidden files along with the rest. rmdir
will refuse to delete the folder if there is anything in, even hidden files so it serves as a additional protection in cases like these. Of course, you could just do rm -ri
if you wanted to be really careful, but personally, I find rmdir
much faster.