Delete Directories From The Terminal In Linux

In your Linux journey, you’ll eventually want to delete directories as you do some housecleaning. Keeping your computer tidy makes you more efficient. Deleting directories you no longer need helps keep your system tidy. 

It’s easy enough to manage and remove directories while you’re in your graphic file manager. Though sometimes, if you’re managing files in the terminal, you might just as well learn to manage directories while you’re in there. It’s not too terribly difficult.

As an example of why this is worth knowing, you may be working with a headless system, something without a GUI desktop environment. In that case, you will have no choice but to delete directories from the terminal. It’s just something you’ll come up against as you learn file management.

Either way, being able to delete directories from the terminal is a skill that comes in handy, a skill that you should know. And so it should be something you have in your toolbox.

The tools we’ll be using for this article are rmdir and rm. They’re both basic commands that have existed since the earliest of Unix days, and they’re both useful commands today.

The rmdir command describes itself as:

rmdir – remove empty directories

And rm describes itself as:

rm – remove files or directories

So, with that in mind, let’s jump into the exercise.

Delete Directories From The Terminal:

Deleting directories from the terminal obviously requires said open terminal. 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.

The first command is really simple. If it’s an empty directory that you want to delete, you can use the rmdir command. As you read in the intro, the directory MUST be empty for this command to work. It’s also really simple to run:

So long as the directory is empty, you should be all set to go. If the directory you want to delete is not empty, you have to use the rm command. It’d look like this:

If you’re curious, the -r flag means recursive – it’ll even delete directories (and the files within them) within the directory. The -f flag means force – it should delete all files and directories no matter what and without any confirmation.

If you’re curious about either of those two commands, and there should someday be an article about ‘rm’, and for now you can just check the manual. You’d use either man rmdir or man rm. There’s not much to the first, and the latter is complex enough to warrant its own eventual article.

Closure:

Whoop! There it is! It’s another article in what’s turning into quite a long list of articles. If I’m going to keep this up for a full year, I might just as well have fun with it – and this was a nice, easy, and fun article. It’s mostly aimed at new users, as long-term users would hopefully already know how to delete directories from the terminal.

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.

How To: Properly Delete a User’s Account

Today’s article will show you how to properly delete a user’s account. It’s a pretty basic task and an astute observer would note that I’ve not yet written an article about creating user accounts. I may have to write said article at some point, because why not? This promises to be a pretty easy and brief article!

When you install some software, it may add a user. When you remove that software, it may just leave that user behind. You may have multiple people using your devices, or you may be working in a corporate environment. Either way, there comes a time when you may want to clean house and delete user accounts that are no longer necessary.

It can be just a little tricky to properly delete a user’s account, so I figure it’s something worth covering. The tool we’ll be using is ‘userdel‘ and my checking indicates it’s universal. Let’s get to it!

Delete A User:

I’m gonna assume that you already know the name of the user you’d like to remove from your system. With that information in hand, let’s open the terminal by pressing CTRL + ALT + T on your keyboard. 

Once you have the terminal open, you can do a basic user delete with:

If the user has a /home/user directory, you can delete that at the same time with this:

Seems nice and easy, right? Well, before you should run any of those commands you should be sure that the user is both not logged in and has no processes running in their name. If you do have either of those things, you will want to run this command before running either of the userdel commands above:

You can also try the -f (force) option with the userdel, but I’ve never had good luck with that. So, your better using killall before you use userdel. If you’d like to try it, here it is:

And that’s actually everything. There’s likely to also be a graphical way to delete users and that’ll depend on your desktop environment. Rather than play around with learning and documenting all those, you can just do it in the terminal where it’s easy enough and equally effective.

Closure:

And now you know how to delete a user account, and how to do it properly. Indeed, this is another article in the books and hopefully this one will help people for years to come. It’s a good idea to not have pointless users around on your system. If they exist, they can be used.

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.

Subscribe To Our Newsletter
Get notified when new articles are published! It's free and I won't send you any spam.
Linux Tips
Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.