1

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?

manuzhang
  • 317
  • 1
  • 3
  • 12

3 Answers3

5

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.

janmoesen
  • 2,710
  • 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
1

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.

user47812
  • 33
  • 5
0

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.

psusi
  • 17,303
  • 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 01: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 02: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. – ctrl-alt-delor Jul 09 '14 at 11:56