Let’s Make The rm Command A Little Safer

In today’s article, we will discuss a simple trick that will help you make the rm command a little safer. This isn’t something everyone will do, but it might be something a cautious user might do. It might also be something a new user might want to consider doing. After all, you can’t be too safe!

Now, when I say safe, I mean preventing you from accidentally removing files you don’t want to delete. I do not mean safe as in security. I mean safe as in preserving data that is important to you. This isn’t a foolproof method, but it gives you a chance to rethink things.

Obviously, we’ll be using the rm command. Don’t worry, that’s not something you’re going to need to install. It’ll be there with your distro as a part of the standard tools, probably from the nice GNU folks.

For those that don’t know, the rm command is a terminal-based command used to remove files and directories. It does exactly what you tell it to do and sometimes you may tell it to do things you don’t want it to do. Either way, the man page (man rm) describes the rm command succinctly:

rm – remove files or directories

See? Nice and simple.

We’ll also be adding an alias. I intend to write a good article about aliasing things, but this is not that article. Don’t worry, you won’t need to know a whole lot about aliases in order to follow along with this article. I’ll make it nice and simple.

Make The rm Command A Little Safer:

As mentioned in the preamble, the rm command is used in the terminal. So, of course, you’ll need an open terminal for this one. It won’t be too complicated, so press CTRL + ALT + T and your default terminal should open. If it doesn’t, find it in your software menu and open it that way.

NOTE: This article relates to the removal of files over which you the user have control, eg ~/home/<your-username>. If you’re removing files with sudo, root, or as another user, the rm command will function as normal.

Alright, so what’s an alias? An alias is a substitution. You can create an alias that inputs ‘foo’ even though you typed ‘bar’, and that’s the trick we’ll be using to make the rm command a little safer for you. If you don’t do this and you remove important files, all I can say is I told you so! 

I’m going to assume that you have Nano installed. If you do not have Nano installed, you can use a different text editor. For simplicity’s sake, we’ll just go over doing this with Nano.

Let’s Install Nano (With Some Bonus Information)

With Nano installed, your first command is going to be opening up your ~/.bashrc file for editing. You do that with this command:

Yes, the . means that it is a hidden file, but Nano finds it just fine.

Now, you want to use the arrow keys to scroll to the absolute bottom of that file and add the following line:

Next, you’ll save the edited .bashrc file by pressing CTRL + X, then Y, and then ENTER.

With that done, you’ll need to tell the system to reload the .bashrc file. You do that with this command:

Now, when you use the rm c