DEV Community

Cover image for My favorite Linux command to run on a VM
MilesWK
MilesWK

Posted on

My favorite Linux command to run on a VM

I have just started focusing on Linux (because they are everywhere) and specifically using VMs. Now, I was reading a Linux command book, when the command, rm -rf appeared. This is where things took a fun turn.

Disclaimer: Don't try anything here. There is a reason why I only do this on virtual machines. :)

First off, allow me to introduce myself. I am MilesWK and I am a programmer and musician. I have had a love of computers and what makes them "tick" for a long time now.

So I had just learned about this new command called rm -rf. Okay, cool. Next I learned about sudo. (can you see where this is going?)

Naturally, I put the two together to make this:

sudo rm -rf \
Enter fullscreen mode Exit fullscreen mode

Pressed enter and found out that I needed --no-preserve-root

Okay, fair. Finally I entered

sudo rm -rf --no-preserve-root \
Enter fullscreen mode Exit fullscreen mode

Now, for those who haven't pieced everything together, let me break it down,

  • sudo makes it so you can edit EVERYTHING (almost) because you are at root level of the computer. Basically like "Run as administrator but better."
  • rm is the command to remove a file at a given path
  • -rf is removing a folder (and all the contents) instead of a file
  • \ is the path you are currently at. So in this case, the base computer
  • If you just ran this like it is right now, it would give you a warning. So we need to disable that with --no-preserve-root

Putting it all together, and pressing enter, deletes EVERYTHING. Depending on how fast the VM is, it can take about a minute to a minute and a half. As it works down the files, you can watch the backdrop disappear, apps start to go missing, and last but not least, the entire thing go black.

Would I ever try this on a REAL Linux machine? No! Of course not!

For some reason this is just the first thing that I decided to make a post about!

Thanks for reading! Post any questions in the comment section below! :)

Top comments (0)