Mailinglist Archive: opensuse (924 mails)

< Previous Next >
[opensuse] Re: add prompt to rm command

It would appear that on Oct 22, Cristian Rodríguez did say:

El 18/10/12 04:25, e-letter escribió:

How to add a verification prompt to the command 'rm', asking whether
the file is really to be deleted?

That happends when you use the wrong shell, do not do that ! :-)

use something proper like ZSH.

$ rm *
zsh: sure you want to delete all the files in ./logs [yn]?

What the {expletive deleted} does the OP's choice in shells got to do with it??

That is a function of the rm command itself...
I can't say for sure about ALL shells, but in bash, the way to get rm
to run in interactive mode by default is to use the alias command.
Here is an example of how to do that in a temporary way:

Note: first I'll use the bash command to open a child shell so that I can
ditch interactive mode just by exiting back to the parent shell...

JtWdyP -> ~/tmp
JtWdyP -> ~/tmp
alias rm="rm -i"
JtWdyP -> ~/tmp
ls tst
JtWdyP -> ~/tmp
rm tst
rm: remove regular file ‘tst’? n
JtWdyP -> ~/tmp
JtWdyP -> ~/tmp
rm tst
JtWdyP -> ~/tmp
ls tst
ls: cannot access tst: No such file or directory
JtWdyP -> ~/tmp

If I actually liked that durned interactive prompt getting in my way, I'd put
the ' alias rm="rm -i" ' command in my ~/.bashrc. Then every time I opened a
new bash shell it would automatically have the "rm" command aliased to "rm -i"

As far as I know, that method works with most shells except that the name of
the rc file would vary... In your case Cristian, I'd expect you would find
something similar in your ~/.zshrc if you looked for it...

| --- ___
| <0> <->
| ^ JtWdyP
| ~\___/~

<< there's nothing like an idiot who thinks he knows everything, of >>
<< course, if I actually knew everything, I'd know I was an idiot. >>
< Previous Next >