Protection from the dreaded "rm -fr /"

Mark Murray markm at FreeBSD.ORG
Mon Oct 4 01:10:42 PDT 2004


Thomas David Rivers writes:
>   If I'm remembering correctly - the historical way to
>  do this is to alias the "rm" command to something that
>  else that checks the arguments and complains appropriately
>  (and then executes /bin/rm.)   Typically with just a shell
>  alias.  That keeps you from accidently doing something. 

Yeah.

$ alias rm="rm -i"

and you get the annoying  "confirm all deletes" behaviour.

>   Just thinking that putting extra "smarts" into a utility
>  isn't the typical "UNIXy" way to do this.  Let each tool
>  do the one thing it does really well.. 'rm' removes; let
>  it remove.

Right. There are SO many special cases here that rm cannot possibly
catch them all:

# cd / ; rm -rf foo/ *
                    ^
                    This space is a typo.

>   I think, in the old "UNIX Review" magazine (what - almost
>  15+ years ago now?)  There was a couple of examples of this.

Many others as well.

"Windows' job is to prevent you from shooting yourself in the foot. With
UNIX, the idea is to make damn sure that there is a hole in your foot with
the greatest possible efficiency." (Paraphrased)

I've typed "rm -rf *" in the wrong place. ONCE. I learned Unix-fu from that
experience. Now, if I type "rm <anything>", I wake up.

M
--
Mark Murray
iumop ap!sdn w,I idlaH


More information about the freebsd-hackers mailing list