How dangerous is this bash script?

WARNING: A dangerous script. Do not run from the command line!

Saw this in an email for company jokes. Can someone explain to me why this bash script is more dangerous than the regular "rm -rf" command ?:

nohup cd /; rm -rf * > /dev/null 2>&1 & 

In particular, why is nohup used and what are the elements at the end?

WARNING: A dangerous script. Do not run from the command line!

+7
source share
5 answers

2>&1 takes stderr (file descriptor 2) and redirects to stdout (file descriptor 1). & itself puts the rm command in the background. nohup allows you to continue working even after the user who launched it logs out.

In other words, this command does everything possible to destroy the entire file system, even if the user ragequits their terminal / shell.

+4
source

You can try something less dangerous:

 nohup cd /; find * >/dev/null 2>&1 & 

I get this:

 nohup: ignoring input and appending output to `nohup.out' nohup: cannot run command `cd': No such file or directory [2] 16668 

So, the nohup part does nothing, it causes only an error. The second part (the original script) tries to delete everything in your current directory and cannot be stopped on Ctrl-C because it works in the background. All its output is redirected to void, so you do not see messages about missed accesses.

+6
source

The joke seems to be broken, obviously it has not been verified, he meant

  nohup sh -e "cd / ; rm -rf *" > /dev/null 2>&1 & 

or

  nohup rm -rf / > /dev/null 2>&1 & 

otherwise nohup cd /; part is considered a separate shell. and the second line just spawns rm -rf *, which is recursive rm of your current directory (except for files with a name starting with.)

+3
source

nohup [..] & makes it work in the background even after the user logs out (which makes it difficult to stop, I suppose)

2>&1 redirects stderr to stdout

> /dev/null discards everything that comes from stdout

Basically, the command does nothing, as your file system is slowly crashed in the background.

+2
source

nohup means that it will ignore the hover signal, which means that it will continue to work even if the user is no longer subscribed.

cd / moves the user to the root directory

rm -rf * recursively deletes all files (moves all directories) and force (it doesn't matter if files are used)

The piece at the end redirects the entire output to nowhere. This should essentially format your disk to nothing.

+2
source

All Articles