Given Rm Why Does Rmdir Exist?

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?

4

1 Answer

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Elena Rostova
Author

Elena Rostova

Elena Rostova holds a Master's degree in Public Health Journalism. She covers groundbreaking medical research, holistic wellness trends, mental health awareness, and nutritional science.