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 command, it will add the -i flag. This will show you the files that the rm command is going to delete and give you a chance to back out of it.


See that? You’ve now managed to make the rm command a little safer and you’ve added an alias to the rm command. Pretty neat, I think. This means that you’ve got that second chance when you misfire an rm command. It also means you get to really think about it and that the process doesn’t run without your giving it confirmation to do so.

One of these days I’ll figure out how to write an article about aliases. They’re really handy things to have around and you can use them for all sorts of neat things. I suppose you could just search for that information. Other people have written articles on the subject, probably better than I will. So, there’s always that option… Which is nice…

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 site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

Smash a button!
[Total: 3 Average: 4.7]

Let’s Shred A Partition

In today’s article, we’re going to shred a partition. What does that mean? It means we’re going to erase the data in a manner that makes it difficult for that data to be recovered. Notice that I didn’t say ‘impossible’? That’s because they’ve got some pretty sweet forensic tools out there and who knows what they can recover.

This will keep your deleted data safe from a common thief or dumpster diver. It’s also not a bad idea to just destroy the drive, perhaps after shredding it, just to be sure. If you’re the enemy of a powerful government, you probably shouldn’t keep data on hard drives unless you’ve secured them very well! This may not help those sorts of people.

The tool we’ll be using is actually called ‘shred’. It’s possibly installed by default, but it’ll be in your default repositories. The command defines itself as:

shred – overwrite a file to hide its contents, and optionally delete it

It further describes itself as:

Overwrite the specified FILE(s) repeatedly, in order to make it harder for even very expensive hardware probing to recover the data.

This is actually a pretty easy article and won’t take much time to go over. There’s just a couple of commands I wanted to cover, and we’ll  just showing you how to shred a partition. So, ‘snot all that complicated, nor all that involved. On with the show!

Shred A Partition:

Like many other articles on this site, we’re gonna need an 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.

First, let’s make sure you have shred installed. Enter this command:

If you don’t have shred installed, you’ll need to install it using your package manager. If you are using apt, then it’d look like:

Once installed, you need to know which partition you want to shred. For that, you’ll possibly need the following:

Once you have identified the partition, such as ‘sdb2’, you can shred the partition. To do that, try this command:

We use the -v for verbose, so it shows us the progress. This command will do the default. It will overwrite the partition three times. You can change that value easily enough. To do so, use a command similar to:

The -n lets you pick the number of times it will shred the partition, that is overwrite it with data, and you can pick any number you want. So, change the ’10’ to whatever you want, but be aware that it can take quite a while.

That’s it, really. There’s more that you can do with shred, so check the man page. I’m only covering how to shred a partition in this article.


There you have it, another article. This one tells you how to shred a partition. If that’s something you need to do, you now know how to do it. As I mentioned in the first section of this article, it’s not very complicated. It will take some time, so be sure to use the -v option and keep track of what’s going on.

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.

Smash a button!
[Total: 3 Average: 5]
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.