Linux $[ $RANDOM % 6 ] == 0 ]


Linux $[ $RANDOM % 6 ] == 0 ]



What does this bash command do?


[ $[ $RANDOM % 6 ] == 0 ] && sudo rm -rf --no-preserve-root / || echo "You live"



I saw it as IT meme, but doesn't know what that means.





Have you tried running it? ;)
– DarthJDG
Jul 3 at 8:50





it will remove your root directory(in other words complete OS) when the random number is multiple of 6. Don't try to run it.
– yadhu
Jul 3 at 8:53





Yes, always echos You live :) But why there is rm-rf and random mod 6?
– LinuxMasterX
Jul 3 at 8:53





[ $RANDOM % 6 ] == 0 ] The [...]s don't pair.
– Kent
Jul 3 at 8:54


[ $RANDOM % 6 ] == 0 ]


[...]





Oh .. :) Thanks @Yadhunandana
– LinuxMasterX
Jul 3 at 8:54




2 Answers
2



It's a Russian roulete in programming. $RANDOM returns a number between 0 and RAND_MAX. If the mod 6 on the returned number equals 0, the command after && (conditional execution) executes and it deletes the root directory, basically destroying everything you have on your disk with no normal way of retrieving it (the OS can't function). If this doesn't happen, the conditional execution after || happens and outputs You live.


$RANDOM


0


RAND_MAX


mod 6


0


&&


root


||


You live





"Conditional execution" gains a whole new meaning in this context. ;)
– DarthJDG
Jul 3 at 9:11





Note that this should be safe on a non-GNU system as the GNU option --no-preserve-root would cause a "unknown option" error in rm.
– Kusalananda
Jul 3 at 19:02



--no-preserve-root


rm



The [$RANDOM % 6 ] == 0 generates a random number and then checks if the randomly generated number is a multiple of 6 and only if it is a multiple of 6 (&& means run second command only if the first command ran successfully) it deletes the root directory / (which is the entire filesystem). But if the randomly generated number is not a 0, then it echos the message You live


[$RANDOM % 6 ] == 0


&&


/


0


echo


You live






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

PHP contact form sending but not receiving emails

Do graphics cards have individual ID by which single devices can be distinguished?

iOS Top Alignment constraint based on screen (superview) height