Search code examples
linuxbashrandomcommandroot

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.


Solution

  • 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.