Re: Avoid rm -f *

From: Christian Schneider (strcat_at_gmx.net)
Date: 01/12/05


Date: Wed, 12 Jan 2005 17:30:01 +0100

Thus spake Robert Katz (katz@hp.com):
> Stephane CHAZELAS wrote:
>> Switch to zsh and zsh will ask you for a confirmation if you
>> attempt to remove every file in a directory (using rm):
>>
>> ~$ rm *
>> zsh: sure you want to delete all the files in /home/chazelas [yn]?
>
> Where is that message being printed? to /dev/tty? And what are they
> doing to return after a single keystroke (no enter key needed)?

#v+
   /* zsh-4.2.2/Src/utils.c */
   1535 checkrmall(char *s)
   1536 {
   1537 if (!shout)
   1538 return 1;
   1539 fprintf(shout, "zsh: sure you want to delete all the files in ");
   1540 if (*s != '/') {
#v-
The message would be printed to stdout.

#v+
   /* zsh-4.2.2/Src/utils.c */
   1552 fputs(" [yn]? ", shout);
   1553 fflush(shout);
   1554 zbeep();
   1555 return (getquery("ny", 1) == 'y');
   1556 }
#v-
A single keystroke expect ``n'' or ``y'' won't work (respectively has no
effect).

#v+
[dope@painless:~/tmp/foo]% touch file-{1..10}
[dope@painless:~/tmp/foo]% ls
file-1 file-10 file-2 file-3 file-4 file-5 file-6 file-7 file-8 file-9
[dope@painless:~/tmp/foo]% rm *
zsh: sure you want to delete all the files in /home/dope/tmp/foo [yn]? n
[dope@painless:~/tmp/foo]% ls
file-1 file-10 file-2 file-3 file-4 file-5 file-6 file-7 file-8 file-9
[dope@painless:~/tmp/foo]% rm *
zsh: sure you want to delete all the files in /home/dope/tmp/foo [yn]?
[dope@painless:~/tmp/foo]% ls :(
file-1 file-10 file-2 file-3 file-4 file-5 file-6 file-7 file-8 file-9
[dope@painless:~/tmp/foo]%
#v-

-- 
[dope@painless:~]% :\)
zsh: command not found: :)
[dope@painless:~]%