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.

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

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.

  The 12 Lords of the Programming World

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.

Join Our Community Of 350,000+ Linux Lovers by liking us on Facebook, or follow us on Twitter, Google+ and Instagram.

If you liked this article, sign up for the fossmint newsletter for handpicked selection of stories from FossMint delivered to your inbox every day.

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.