The rm command

Discussion in 'Beginner Tutorials' started by Rob, Jul 9, 2013.

  1. Rob

    Rob Administrator Staff Member

    Messages:
    573
    Likes Received:
    186
    Trophy Points:
    43
    '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.

Share This Page