General Discussion

Do You Know Some Crazy “rm -rf” Stories?

Linux rm -rf Command
Written by Martins D. Okoi

The rm -rf is one Bash command similar to the DROP SQL command. Unless you have a replica (backup) of your database table, you will lose all the data.

rm -rf is a command that when invoked without root privileges will remove all the folders that the user has access to. When invoked with root privileges, it will obliterate your hard drive.

I’ve not been unlucky to make the mistake of running this code on a production server before, but not everyone has been that lucky. Here are some interesting rm -rf stories you might find relatable.

1. Thomas & the CLI-based Trash Program

Thomas was in his College Unix lab working on a midterm project for which he was connected to a server in an adjacent lab using PuTTY + RealVNC.

His project was straightforward: Create a “trash” CLI program that takes a list of file paths and moves them to a ~/.trash directory. You can then “empty the trash” which executes rm on the directory. He had the first part done and was completing the empty command.

Somehow he set the wrong variable which left the remove path as / and he had sudo access. Nothing happened when he ran the code at first but shortly after the became glitchy and began to display static. Ctrl + C couldn’t help. Next, the monitor went blank and disconnected.

  12 Reasons to Switch Over to Linux

His code ran a sudo rm-rf / and that wiped all the data on the server. Luckily for Thomas, he was working on the department’s test server and was able to recover the data from backup disks. He didn’t lose his admission.

2. A Clean Wipe During A Backup Session

Alex was a network administrator at a company that backed up their machines via scripts. On one fateful Friday, he upgraded the script with the text, rm -rf ${DIRECTERY}/ instead of rm -rf ${DIRECTORY}/ – making the command update to just rm-rf because the ${DIRECTERY} became an empty string.

The backup session began later that night and before Alex knew it, all the machines on the network were wiped clean! Luckily for him, the company backs up files every hour so no much damage was done. That notwithstanding, it was a busy weekend. Quite ironic that a backup job would wipe systems clean, right?

3. The Automated Recursive Cleaner

One time Eric was working on a file server and wanted to automatically clean up some files every week or so. He planned his line and tested it with the aim of removing only relatively older files. His work was within a single directory so he didn’t think anything could go wrong. Well, he later found out he guessed wrong.

  Where Will You Find the World’s Fastest Linux Supercomputer?

He ran the following command and it worked. Next, he manually added the line in the crontab and that was when he mistakenly replaced the . with a /.

# find . -type f -name * -ctime -60 -exec rm -rf {} \;

Fast forward to a week later and a significant number of files were gone. What was worse is that they got deleted at what seemed to be a random pattern so his thought the company was being hacked until when he ran a code check and realized he was the hacker.

Luckily, he kept external backups every day so he was able to fix his mistake. Since that day you can bet he has been super careful with the commands he runs with admin privileges.

The 2 main take-home points existing in the above stories are 1, always double-check your code and its possible resultant effect and 2, always keep your backups as current as possible because you never know when they will come in handy.

Do you know any crazy rm -rf stories from experience or elsewhere? Share them with us in the comments section.

Your Unwavering Support Matters a Lot:

The cost of maintenance is skyrocketing as more readers are coming on board and the ad service that we employ in order to generate revenue is unfortunately no longer sufficient and this is especially due to the increased use of ad-blockers.

We humbly request that you consider disabling your ad-blockers to support us financially or by donating as anything from $1. Your donation(s) will go a long way in supporting FossMint and sister site, TecMint, in running efficiently. Thank you.

Make a Contribution via PayPal


Top Deals

About the author

Martins D. Okoi

Martins Divine Okoi is a graduate of Computer Science with a passion for Linux and the Open Source community. He works as a Graphic Designer, Web Developer, and programmer.