WARNING: Dangerous script. Do not run from your command line!
Saw this in a company joke email. Can someone explain to me why this bash script is more dangerous than a normal ‘rm -rf’ command?:
nohup cd /; rm -rf * > /dev/null 2>&1 &
Particularly, why is nohup used and what are the elements at the end for?
WARNING: Dangerous script. Do not run from your command line!
Solution
2>&1
takes stderr (file handle 2) and redirects to stdout (file handle 1). &
by itself places the rm command in the background. nohup allows a job to keep running even after the person who started it logs out.
In other words, this command does its best to wipe out the entire file system, even if the user ragequits their terminal/shell.
Answered By — Marc B
Answer Checked By — Dawn Plyler (FixIt Volunteer)
This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0