views:

323

answers:

3

What are the worst/best unix shell nightmares? My favourites are:

  • rm -rf / tmp/foo (deletes everything if you are root; typo :-( )
  • rm -rf .* (deletes everything if you are root; not just all hidden files)
  • Files in * that are used as parameters, e.g. after touch -- -rf, rm * eventually evaluates to rm -rf foo bar
  • cat foo | sed 's/foo/bar/g' > foo (deletes foo)
  • some_command > /dev/sda

WARNING: Do not try any of these or the following commands!

+3  A: 
:(){ :|:& };:

Warning: DO NOT DO THIS

This is a fork bomb. The equivalent of:

while (1) {
    fork();
}

Only do it as a test on a machine you have physical access to. You need to be able to hard reset :D

Sean Bright
I also thought about that one, but when do you type in that by accident ;-)?
Johannes Weiß
You never mentioned "by accident" :)
Sean Bright
So for those of us who might just be curious enough to ssh into our boss' terminal and try that out, what does that do?
Scottie T
Johannes, haha yeah i also thought whether i should answer with that :p though i would probably never write it by accident. but i think sean is right: you omitted to mention you meant "accident" stuff :)
Johannes Schaub - litb
@Scottie: see http://en.wikipedia.org/wiki/Fork_bomb
agnul
Classical Fork Bomb :D. Run "ulimit -u 30" if you want to try this one out... You'll limit the fork bomb to spawn only 30 process
skinp
I ran this while SSH'd into my home machine from work before I knew what it was. When I got home the fan in the machine was running so fast it sounded like a jet engine in my office.
Sean Bright
yeah haha i once run that code too, when i thought my machine won't crash and i could easily kill shell (oh no, i could not!) :p
Johannes Schaub - litb
I think this is lcamtuf signature, right ?
MatthieuP
+1  A: 
dd if=/dev/urandom of=/dev/hda

Wipe out entire disk with random data.

skinp
+1  A: 
cat /dev/random > /dev/hda 
# oops, why don't i hear sound? oh noes, i meant /dev/dsp!

The code above was given in a suse linux manual as an example why working as root is dangerous. I guess the user doing that mistake learned something for life.

Johannes Schaub - litb
that's why you should not work as root ;-)
Joachim Sauer
saua, you wrote that while I was writing the same thing in the question.
Paul Tomblin