Linux: The 'rm' command

'rm' is for removing or deleting files. That means, sending them into non-existence, oblivion, bye-bye.


The correct use of 'rm'
So you have to be careful with 'rm'. That's why we put an entry into our '.bashrc' file: alias rm='rm -i' so that it asks you if that's what you really want to do.

If you created a file called 'bad_jokes' and you wanted to get rid of the file, you would type rm bad_jokes, and because you made an alias, it will ask you.

rm: remove `bad_jokes'?:

You would press the the 'y' key unless of course you remembered that you have a real good one in there and then you would answer: with the 'n' key. Actually, any key other than 'y' is the same as responding with the 'n' key, so if you accidentally type 'w', don't worry.


'rm' - some words of caution
You can also do stuff like rm b* with the asterisk, but I would use my best judgment with that. You may get 'y-itis' and just keep pressing the 'y' key. I have done that before.
Occasionally, when I've used the text editor 'joe' a lot I end up with a lot of files that end in a tilde (~). You get files like 'note_to_myself1' and if you've modified it, another one 'note_to_myself1~' Then I decide that I don't want all of those ~ files littering up my directory and I innocently type: 'rm note_to_myself*' and then 'y' 'y' 'y' and then I realize too late and my brain types: 'Y did you do that!!' The problem is that 'note_to_myself2' contained my important plans for taking over the world and 'note_to_myself3' contained a note about how much money I owe at the dry cleaners. Maybe taking over the world can wait, but my dry cleaner's not going to give me my suits the next time unless I pay him.

There's another case of 'rm' that's potentially more dangerous than the 'rm *' case. That's adding the '-f' option on the end. If you do this, it will override the '-i' option and won't ask you anything. It just goes ahead and deletes the files in question. For example, if you were in a directory and typed 'rm * -f' you would delete everything, no questions asked. I generally use the '-f' option very sparingly, like when Valentine's day falls on Friday during leap year and coincides with a full moon.

Also, please be very careful when you're using the 'rm' command as 'root'. You could do some very serious system damage if you delete the wrong files. Wait until you have some experience before you start removing files 'by hand' as 'root'. Use the configuration tools provided in your version of Linux to un-install programs that you don't want.

  • 2 Users Found This Useful
Was this answer helpful?

Related Articles

Adding a range/block of ips

As an example to add a /24 253 ips to a linux server follow these setups. We'll use...

How can I check my hard disk usage in Linux?

Once you are connected to the server via SSH, run the following command:# df -hThis will output...

Test If Linux Server SCSI / SATA Hard Disk Going Bad

One of our regular sends us a question: How can I test if my hard disk is going bad? I see few...

How to Find Out Hard Disk Specs / Details on Linux

Linux comes with various commands to find out information about your hard drive. I recommend...

Monitoring Hard Drive Health on Linux with smartmontools

S.M.A.R.T. is a system in modern hard drives designed to report conditions that may indicate...

Powered by WHMCompleteSolution