[Nottingham] *nix most dangerous command line commands...

Martin martin at ml1.co.uk
Sat Jun 14 12:06:48 UTC 2014


On 14/06/14 11:55, Robert Mitchelmore wrote:
> This is a terrible idea, but an entertaining one.
> 
> $ mkdir foo
> $ cd foo
> $ touch -- -i
> $ touch importantstuff
> $ rm -rf *
> remove importantstuff? n
> $

For those missing the geekery giggle:

The "rm -rf" should not be asking any questions about deleting
everything... Yet how come the user prompt?...


The secret is in the shell globbing... ;-)

And that highly highlights a useful power of bash and also a very
annoying weakness for parameters doing the unexpected because of a
myriad of 'special interpretations'...

To try to protect against that, I usually bracket all parameters with ''
or "" wherever possible...

I may yet move to python!


Good one thanks,

Cheers,
Martin



From:

man rm:

       -i     prompt before every removal

       -I     prompt once before removing more than three files, or when
removing recursively.  Less intrusive than -i, while still giving
protection against most mistakes

       --interactive[=WHEN]
              prompt according to WHEN: never, once (-I), or always
(-i).  Without WHEN, prompt always

       --one-file-system
              when removing a hierarchy recursively, skip any directory
that is on a file system different from that of the corresponding
command line argument

       --no-preserve-root
              do not treat '/' specially

       --preserve-root
              do not remove '/' (default)

       -r, -R, --recursive
              remove directories and their contents recursively



Aside:

I have "rm" aliased to be "rm -i"... All good but *even more dangerous*
when using /other/ systems where "rm" is plain unaliased "rm"...



-- 
- ------------------ - ----------------------------------------
-    Martin Lomas    - OpenPGP (GPG/PGP) Public Key: 0xCEE1D3B7
- martin @ ml1 co uk - Import from   hkp://subkeys.pgp.net   or
- ------------------ - http:// ml1 .co .uk/martin_ml1_co_uk.gpg



More information about the Nottingham mailing list