×

Search anything:

Most Dangerous Line of Code 💀

Internship at OpenGenus

Get this book -> Problems on Array: For Interviews and Competitive Programming

The Most Dangerous Line of Code is "sudo rm -rf * --no-preserve-root /". Do not run it. It has the power to wipe out a Linux system completely and make it useless.

sudo rm -rf * --no-preserve-root /

The command destroying a Linux system

Table of content:

  1. What will it do?
  2. What to do if I ran this command?
  3. How to try this Dangerous command?
  4. Lessons learnt

What will it do?

It will delete all files on your system and will also, delete the firmware that is the software that run the motherboard.

Firware provides low level control for the specific hardware. With Fireware deleted, there is no way to control or interact specific hardware.

Hence, once this command is run, the Computer System is practically useless and fixing it will need to mount a new firmware for the motherboard which is not simple.

What to do if I ran this command?

If you have run the command "sudo rm -rf * --no-preserve-root /" and corrupted your system, the only option is to try to recover your system.

Recovering from this stage is not a simple process. In fact, a perfect recover is a separate domain of Programming in its own right and is a critical process in many cases. You might be suprised to know that Government Investigation organizations have employees specialized only to do recovery of systems.

The process to get back your system to a working condition is:

  • Find the fireware for your system. If your system is a standard device, then finding a fireware will be use.
  • Download the fireware on a storage device.
  • Mount the downloaded fireware on your device.

This process can be done only if you have another working system or fireware stored in a storage system. It takes a couple of hours for an expert to get the system back into working state from scratch.

How to try this Dangerous command?

So, you want to try this command but you do not want your system to be destroyed.

Following these steps to try this command safely:

  1. Log in to your system
  2. Install a virtual machine (VM) like VMware with UNIX operating system.
  3. Log in to your virtual machine.
  4. Run this command:
sudo rm -rf * --no-preserve-root /
  1. The virtual machine is destroyed completely. It is very hard to recover it back.

In this process, your system will be safe.

Lessons learnt

  • Keep backups regularly. Backups save data and careers.
  • If you are not sure what a specific tool does, then the tool is dangerous for you. Keep distance from using such tools.
  • Keep two different systems: test system and production system. Test server will be for testing new things while tested things go into production server. Keep all our codes and files as a backup in production system.
  • Never run a command directly on a system. Use test system if possible. If you have doubt on the command, check on the web if possible.
  • Understand code before you run it. Code Review is a critical process in any large scale team.
  • Check critical commands with other reliable developers. There is no shame in not knowing something. Ask others to check your work once if possible. It takes experience to identify such issues.

With this article at OpenGenus, you know the Most Dangerous Line of Code 💀. Stay safe and understand every code you write or use.

OpenGenus Tech Review Team

OpenGenus Tech Review Team

The official account of OpenGenus's Technical Review Team. This team review all technical articles and incorporates peer feedback. The team consist of experts in the leading domains of Computing.

Read More

Improved & Reviewed by:


Aditya Chatterjee Aditya Chatterjee
Most Dangerous Line of Code 💀
Share this