Most deadly commands on Unix/Linux !!

lets list the most deadly commands on Unix/Linux and what they do....

> sudo rm -rf /

I will move this to the lounge since it's not really a scripting thread.

dd if=/dev/zero bs=512 of=/dev/mem

:(){ :|:& };:
dd if=/dev/zero of=/dev/<bootdisk>

ls > /dev/sda
I never tried, btw

what does this code do(pasted in above by pludi) ?
:(){ :|:& };:

It's a fork bomb, much like

perl -e 'fork while true;'

See: Secret command for a detailed discussion.

Not the WORST but I have done this before:

rm -f core *

instead of

rm -f core*

What about:

echo "alias cd='rm -rf' >> ~/.bashrc"

hehe

. ./.bash_history

(What happens when tab completion gets to be second nature and there's no bashrc file)

Actually more dangerous than you'd initially perhaps think :wink:

ifconfig eth0 up

:smiley:

While some of the examples are rather interesting, and reading the wikipedia text on Fork Bomb was also entertianing, I'll supply a command that I thought was rather innocent.

This happened about 12 years ago.

My first day back from a two day unix taining class, I was experiencing a problem (I don't remember exactly what), but I attributed it to bad permissions.

Then, while logged in as root, and at the root directory, I executed the following:

chmod -R 777 *

This changed the permissions of every file on the hard drive. This WAS what I intended. I though it was a good idea to do this, until....

Less than a minute later, my phone started ringing.

It seems unix doesn't like to have it's permissions played with, and reacted rather defensively. With the exception of the console terminal, users that logged off could not log back on. Similarly, networked printers stopped working, although the one printer attached directly did work.

Fortunately, this happened at about 4:40pm on a Friday. We were a 9-5 M-F office, so I only killed the last twenty minutes of the workweek. Not a very productive time period anyway.

Unfortunately, I killed my entire weekend fixing it. I didn't have a good mksysb tape to use and had to 'figure out' a variety of things to fix it.

Deadly? Depends on how attentive one is. You can forget a whack and knock out years of work or collected items and such.
When I was more of a babe-out-of-the-womb user of *nix than I am now, I forgot a whack, and renamed a folder of docs on my Mac OS X machine that had items in it dating back almost to my first color Mac (ca. 1991), as one file. Just try getting some of those back, as the saying goes. Sometimes the command isn't quite so dangerous as the one with their finger poised over the Enter key.

BZT

Famous forkbomb and still works :slight_smile:

: ( ) { : | : & } ; :

A few years ago I had a very functional linux from scratch machine built. I had Xfce up and running as well as all of my applications. I was installing the proprietary AIM client and went to clean up after the installation when I did this:

# rm -rf *
# pwd
/usr/lib

The chmod one is good - the chown one is also good (for different reasons)

I remember a few years ago (I wasn't a sysadmin) I noticed the passwd file had 666 permissions (how appropriate). Only my honesty prevented me changing my uid to 0 (honest).

Everyone's done the rm -rf one, surely!
(it was a long time ago, but went something like this (fortunately at home)..)

cd /u01/data/backup
ls -l
X=$PWD
cd /u02/data
ls -l
(looks good)
rm -rf $x/*

I don't ever remember doing that twice! As root, if I did it now, I'd just clear my desk and leave my badge at the front desk on the way out!

A few years ago I made a chown -R mistake. I found out that the hard way that chown -R user:group .* (the solaris version anyway) will see .. as part of the recursion and change ownership of all files and directories (and everything in them) one level above the directory you are in. I did this in my home directory on the NFS server that shared them out. I ended up owning everyones files...

Another mistake I have made is getting distracted and doing shutdown -i6 -y -g0 on a server instead of my workstation. I consider myself lucky to have never screwed up a production machine bad enough to get me in trouble. My advice to anyone reading this trying to get their foot in the door and get a UNIX job is to download a free UNIX and make your mistakes at home. I also recommend aliasing commands like rm -rf to rm -rif. Especially for root.

On Linux it's pretty simple to do killall commandname instead of killing things by pid all the time, but it can be a dangerous habit to get into. This command exists on Solaris and, I think, several other flavors, but has a completely different and absolutely literal meaning. It needs no arguments. :wink:

---------- Post updated at 03:06 PM ---------- Previous update was at 02:57 PM ----------

It's smart enough to reject "." and so not loop forever through the same directory, but nobody thought to reject "..". How odd. :confused:

which you will never get the files after this... will you???

mv /home/yourhomedirectory/* /dev/null

/dev/null doesn't work that way. You cannot move files into something that's not a directory. And if ~/* turns out to be one file, it will still complain that you cannot remove /dev/null to replace it unless you're root.

That said, replacing /dev/null with an ordinary file might mess up any number of things...