fixing rm * (was: Worm/Passwords)
Dennis L. Mumaugh
dlm at cuuxb.ATT.COM
Sun Nov 20 03:15:49 AEST 1988
This dicussion surfaces at least once every 6 months. Gene
Spafford out to summarize and put into the 100 questions
document:
In a job a long time ago in a place far, far away .... Four of
us got bit by the rm * problem within two days. I lost a whole
day's worth of power coding and had to reconstuct an entire
project from memory [see Knuth on the merits of this] when I
typed rm *.c instead of rm *.o.
So, I decided there must be a better way. Since we also had a
set of other similar commands [del and delete for the PDP-10
lovers] we built a trap door into the shell. If the command was
exactly {rm|del|delete} and the glob function returned a true
[expanded a * ? or [ ...] construct] we echoed out to the
terminal the expanded form of the command and a request to
confirm.
e.g the command
rm *.c
whould result in
glob: rm foo.c bar.c barf.c fubar.c unix.c
confirm?
The query would only be echoed if the stdin was a terminal.
Also, it worked ONLY with simple command names, full path names
or alias expansions weren't checked.
We also got bit later by the following:
rm -rf ..
So we had to put a check into rm for that kind of combination.
Yes, we did get a few people who would hit y<CR> by habit. But
only until they did it one too many times. After that they
learned.
--
=Dennis L. Mumaugh
Lisle, IL ...!{att,lll-crg}!cuuxb!dlm OR cuuxb!dlm at arpa.att.com
More information about the Comp.unix.wizards
mailing list