Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
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?. – Faheem Mitha Mar 28 '12 at 12:34
I have an alias rmtil or rmback to do this. So I don't do that again. – richard Jul 9 '14 at 11:50
One approach is to think about the order you type: rm ~ back * enter. – richard Jul 9 '14 at 11:54
up vote 5 down vote accepted

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.

share|improve this answer
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 Mar 28 '12 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 my from myself.

share|improve this answer
nice tip, cheers! – manuzhang Mar 29 '12 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.

share|improve this answer
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 Mar 28 '12 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 Mar 29 '12 at 1:41
if you do this tens of times everyday, I'm not sure it will even go through your mind. :) – manuzhang Mar 29 '12 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 Mar 29 '12 at 14:19
find a way to remove fear, this is the way to true enlightenment. – richard Jul 9 '14 at 11:56

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.