M HYPE SPLASH
// general

Given rm why does rmdir exist?

By Abigail Rogers

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

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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