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! :)

Do your career a big favor. Join DEV. (The website you're on right now)

It takes one minute, it's free, and is worth it for your career.

Get started

Community matters

Top comments (0)

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay