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.
Umm…
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!
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 CTRL + ALT + T and your default terminal should open.
Now, with your terminal open, let’s use ‘rmdir
‘ and learn how to remove a directory. In its basic form, the command is:
rmdir <directory>
This works if it’s a path you want to specify:
rmdir /path/to/dir
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:
rmdir -v /path/to/dir
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:
rmdir -p /path/to/dir
Of course, if you want confirmation of what’s being deleted, try:
rmdir -p -v /path/to/dir
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.
Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your own site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.
Today we'll cover one way to enable or disable your network interface in the Linux…
Today's exercise is a nice and simple exercise where we check your NIC speed in…
Have you ever wanted to easily monitor your wireless connection? Well, now you can learn…
I think I've covered this before with the ls command but this time we'll count…
Today we'll be learning about a basic Linux command that's known as 'uname' and it…
If you've used hardinfo in the past, it may interest you to know that hardinfo…
View Comments
You forgot about rm -rf
It gets worse! I tend to look to see if I'm duplicating a topic, but I've actually covered this topic before.
Where I included 'rm' and 'rmdir'... Though it was a fairly short article and this one covers rmdir better than the last one.
LOL I did not realize it was duplicating a previous article. In my defense, I've written hundreds of articles.