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.
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.
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.
I was kinda hoping for at least one story where the word ‘luckily’ wouldn’t be applicable.
IKR
I’m waiting to come by such a story.
One time I accidentally dd to my system disk instead of installation USB 🙂
I don’t know about “sudo rm -rf /” but “sudo rm -rf etc” I did… In the “wrong place” at that… It was a long, lonely and cold night… ;}
Lol
I imagine it’s one you wouldn’t forget quickly too.
A long time ago accidentally I run mkdir ~. So I thought I’m just gonna remove it rm -rf ~. This started to remove my home directory. Since then I move everything in tmp.
I was showering a friend this command in Windows subsystem for Linux figuring I would just reinstall the distro. Well /mnt/c leads to Windows and I frantically Ctrl-C’ed as I realised it was trying to delete my C drive. Thank goodness windows wouldnt allow that. Although pretty sure if I let it get to my media drive it would have wiped it out!
Ha! That was a close one.
I’ve seen in an irc room , a user asked for help with a new install of Linux that wasn’t working correctly.
1st answer was, it was a known issue and removing the French language package will fix it, the command given
Sudo rm -fr /