I intended to delete all the backup files in a directory, so I was going to type rm *~ in the terminal. Unfortunately, I hit the Enter before hitting the tilde and unhappy things happened. Although, I've recovered all deleted files I really don't want it to happen again. Could I forbid the execution of such a command unless being granted a permission, like that of a superuser?

  • 2
    Obvious comment, but learn and use distributed version control, and these things will become less of an issue. See also trash-cli if available for your distribution. See also Where do files go when the rm command is issued?. Commented Mar 28, 2012 at 12:34
  • I have an alias rmtil or rmback to do this. So I don't do that again. Commented Jul 9, 2014 at 11:50
  • One approach is to think about the order you type: rm ~ back * enter. Commented Jul 9, 2014 at 11:54

3 Answers 3


I am not a fan of overriding built-in commands, but in my .bashrc (part of Tilde, my "dot files") I explicitly do this:

alias rm='rm -i';

This makes rm ask for permission before deleting. It has saved me a few times. You can always override with rm -f.

  • Efficient solution, which I thought most people had... With ZSH, aliases have to be put in ~/.zshrc like this: alias rm='rm -i' or alias rm="rm -i"
    – tiktak
    Commented Mar 28, 2012 at 12:15

In Bash I simply escape the rm command to override the -i option. Like so: \rm file*

I love the -i option. It too has saved me from myself.

  • nice tip, cheers!
    – manuzhang
    Commented Mar 29, 2012 at 2:48

After you have shot yourself in the foot once or twice, you learn to take your finger off the trigger until you are sure you have it aimed right.

In other words, learn to pause and double check that you got it right whenever you start typing an rm with wild cards.

  • Hey, man. When you are on the freeway of terminal, you can easily get your mind ahead of your finger. It's just happening all the time.
    – manuzhang
    Commented Mar 28, 2012 at 22:30
  • And it seems that part of psusi's answer is that you shouldn't be speeding too fast on that freeway. Slow down and make sure what you're going to do is what you want to do.
    – Dason
    Commented Mar 29, 2012 at 1:41
  • if you do this tens of times everyday, I'm not sure it will even go through your mind. :)
    – manuzhang
    Commented Mar 29, 2012 at 2:46
  • Shoot yourself in the foot a few more times and you will learn to double check. The pain of data loss should make a nerve in the back of your neck twinge and lock up your fingers for a moment as soon as they start typing rm + *.
    – psusi
    Commented Mar 29, 2012 at 14:19
  • find a way to remove fear, this is the way to true enlightenment. Commented Jul 9, 2014 at 11:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .