Open-Source Internship opportunity by OpenGenus for programmers. Apply now.
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 /
Table of content:
- What will it do?
- What to do if I ran this command?
- How to try this Dangerous command?
- 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:
- Log in to your system
- Install a virtual machine (VM) like VMware with UNIX operating system.
- Log in to your virtual machine.
- Run this command:
sudo rm -rf * --no-preserve-root /
- 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.