Today’s article is going to teach you how to remove a directory. This being Linux and rmdir, you can only remove empty directories. That’s okay, that’s still what we’re going to use. I’m pretty sure I’ve explained how to remove files before and, if not, that’s a pretty simple task.
This article is going to be light on details and pretty short. I popped positive on one COVID test and negative on another. I could take a third test, but I really just feel crappy and not all that bad. Still, it’s an excuse to have a nice and easy article! I like those sometimes! My proofreading may be sub-par.
Like I said, we’ll be using ‘rmdir’ and that only works on EMPTY directories. I can’t stress this enough! If there’s a file in the directory, any file, it will not delete the directory.
I do not know the design reason for making ‘rmdir’ (a standard tool in every Linux) only remove empty directories – but I suspect it’s a protection method. It’s protecting itself from you – meaning you must go in and confirm that it is empty and that there are no files remaining that you’d like to keep. After that, you can delete the directory.
That stands to reason and, frankly, it’s the only reason I can think of. If anyone knows the real reason, assuming I am wrong, please feel free to let me know in a comment. I’m quite curious. Ah well… Onto the article!
Remove A Directory:
This article requires an open terminal, like many other articles on this site. If you don’t know how to open the terminal, you can do so with your keyboard – just press
Now, with your terminal open, let’s use ‘
rmdir‘ and learn how to remove a directory. In its basic form, the command is:
This works if it’s a path you want to specify:
If you want, you can use the
-v switch and get a verbose output, telling you what is being deleted. This is probably for the best. So, it’d look like:
But wait, there’s more! What if you wanted to remove all of that, you want to remove
/path /path/to and
/path/to/dir? Well, you can do that:
Of course, if you want confirmation of what’s being deleted, try:
Assuming all those directories are empty, the command will complete itself and remove all the directories in that path. Those are basically all the rmdir commands you’re likely to need, but you can check
man rmdir for more information.
See? Nice and easy. See? You even get an article when I’m dying from the plague! Don’t worry, I’m sure I’ll be just fine. Statistics are my friend at times like this, so my worry level is exactly 0%. The odds of it incapacitating me are negligible and I’m a pretty big fan of math.
I’m vaxxed to the max and even boosted – which only lessens your chance. I’ll be fine. After all, only the good die young! (I am not young, now that I think about it!) I’ll quarantine at home and hope for the best, while monitoring for degradation.