Categories
Linux Video

What Happens When You Run “rm -rf /”

I’ve known for a long time to stay away from the short, sweet and simple “rm -rf /” command.  It deletes every file on any writable filesystem mounted by a *nix system, but what exactly happens if you do run it?   Do green leprechauns jump off the screen to warn you that you shouldn’t do it?  […]

I’ve known for a long time to stay away from the short, sweet and simple “rm -rf /” command.  It deletes every file on any writable filesystem mounted by a *nix system, but what exactly happens if you do run it?  

Do green leprechauns jump off the screen to warn you that you shouldn’t do it?  Not quite.

Here’s a video with the verbose option set to make it a little bit more interesting.  I’m running it in a virtual machine so I can capture video of all the “action” – it was a bit slow to complete, but I’ve gone ahead and increased how quickly it runs to not be nearly so boring.

Enjoy!

At the very end you can see that X crashes on the VM when I click where the trash icon would be. Rebooting results in a GRUB error 15.

If you’d like to hear a horror story about someone running rm recursively, check it out here: http://www.ee.ryerson.ca/~elf/hack/recovery.html

75 replies on “What Happens When You Run “rm -rf /””

Holy shit, you read my mind or something. I was thinking about doing the same thing. I have actually done it before, just to see how much fun I could have, but I didn’t record it or anything. I never thought about doing it in a VM. Very Cool.

I think the most interesting part is that we got to see the operation complete in the terminal: the system was still (minimally) operating, even without any system files left.

Yeah it was fun to watch it the first time around… then I did it on a VM, which was pretty dog slow… it doesn’t seem like it in the video since it’s 2x speed after I type in the password to run a root terminal.

i accidentally created a folder named “*” in /etc folder, and to remove it did “rm -rf /etc/*”, was too late before i even realised what was happening.

@Daeng

That’s a side effect of how Linux handles files on disk. The files wont actually be deleted from disk while a process is still making use of them.

The same is true for upgrades. if you were to overwrite /usr/sbin/apache2 with an updated version, the system will continue to run the old /usr/sbin/apache2 until the process is stopped and restarted.

Which is one of the reasons system updates are less painful than the windows equivalent as we don’t have to reboot to replace files that are currently in use.

I believe the reason it continues to seem to run is because the operation didn’t remove everything. Eventually it got to the “rm” executable and removed that. After that, I don’t believe it can continue the process.

There may still be files left, but you’ve deleted “ls” at that point, so you can’t see them.

That is my theory.

Files are not removed from the disk, they are unlinked from the directory structure. Any file that is still open remains accessible. The errors occur when running processes try to open a file, which, after rm -rf, it can’t find.

It’s more fun to run dd if=/dev/zero of=/dev/sda1 – the machine lives a bit longer since the file system cache isn’t immediately trashed.

I unplugged my hard disk once. There was no swap space on it so it helped delay the inevitable crash a lot.

The kernel spewed a lot of I/O error messages but the console kind of worked for a couple of minutes(X crashed almost immediately).

@Jack. No, if rm says it’s complete, it is complete. rm runs once and doesn’t respawn for every file.

Cool. I recognize the music — it’s a tune called “Popcorn” which was the first song ever to be released that was recorded using electronic instruments. Obviously this is a modern cover of it — who is it???

Dunno about Amiga games, but I’m fairly certain that song appears in tetris, not positive so I might be wrong though…

LOL! That’s great!

In fact, I did just that during the first days of being a Linux user. I thought I was about to remove all the files in the current folder (without being asked a lot of questions) by typing “rm -rf /*”.
Before pushing [ENTER] I actually considered whether or not the “/” was suppose to be there. But then I thought “nah, the system won’t let me remove any critical files without asking me first, would it?”. Well, because of the mysterious non-verbose mode, I didn’t realise what was going on till the operation was completed and the prompt seemed almost as feature rich as MS DOS. Is that you Ballmer, installing DOS on my machine? Echo? 😀

The song *is* “Popcorn”, originally by Billy Preston, and was a minor hit in 1972 or thereabouts. He was a friend of George Harrison and the Beatles, and had quite a successful career, mostly as a studio musician on the keyboards. Died a few years ago.

Yeah, *nix systems just assume you meant to do that, even when you didn’t mean to. I had a good teacher who warned me about that before the distro we were using finished installing, but I imagine anyone who didn’t have a mentor or teacher to guide them has a similar story about wiping out the machine.

@tsella

He mentions in his description that he’s running the command on a virtual machine and recording it with the real one.

The thing is, everyone thinks this is the worst thing to happen if you’re on a *nix system and that for viruses, this is the ultimate achievement.

I think a scarier scenario is ‘rm -rf ~’ because if you accidentally do a recursive ‘rm’ in /, you have a chance to kill it and you can re-install the OS. If you accidentally ‘rm -rf ~’ if you haven’t backed up recently, kiss your docs goodbye.

I know you may be able to recover them but my point is, you don’t need to be root to perform devastating mistakes!

What is actually happening with any “rm” command is the file system is just removing the inode (a special link to the exact address on the hard drive) of the file. The data is still there (and should be able to be accessed if the program knows how to directly access the data) until it is over written by a new file.

Currently running programs will continue to function normally (because they are in memory) unless they need to open a new file not already in memory.

I’ve done this on a Mac, and it was hilarious! The system was mostly usable, although I couldn’t open any new program that wasn’t already open and in memory.

fyi — “popcorn” was not the first “electronic” instrumental to be released to the general public… at a bare minimum, “… [Wendy] Carlos hit platinum sales status with her 1968 recording ‘Switched-On Bach,’ which propelled the Moog synthesizer into the public consciousness and won three Grammy Awards…”

Sad to say, I accidentally did this on a production machine… on the “system disk” in a VAX/VMS system about 30 years ago…. I was on the system disk, doing maintenance (of course), logged in as the administrator and needed to recover some disk space…

well – I got it ALL back, LOL

Luckily the data disk was intact, so I wasted a couple hours reloading VMS from a handful of those HUGE 10 or 12 inch diameter disk packs… I think all the disks I loaded were less than one CD worth of info!!

Luckily my buddies got a kick out of it and there were only like 4 of us using that system… But unlike *NIX the VAX actually DID lock up on us all as the files were apparently not just “unlinked”!

sigh… what a newb I was back then!

enjoy, friends!

I did rm -rf /* on a freebsd server at work thinking I was deleting just the contents of my current directory. Luckily I realized before it got all the way through /bin and stopped it.
To fix it I copied the /bin directory from a sister server onto a samba share on the affected server and then slid it into place. I had to run cp and ls from the samba share in order to accomplish this…

BTW, the song is based on Peer Gynt Suite No. One, the Hall of the Mountain King, by Edward Grieg (late 19th century) and was used in different computer games, such as Manic Miner on ZX Spectrum, besides others

My worst was probably chmod 000 * as root – from root

That was not pretty – as it was not a local machine, the machine was 6 hours drive away.

Not a good position to be in, luckilly we were able to get a contracter in from the area, he was able to login runlevel 2 and start to revert permissions.

Wow … all that spam. I feel bad about breaking the string!

At any rate, I’ll be linking to this site in an hour or so from http://nmwoodworks.com/tech (the tutorial on getting Outlook running on Linux was pretty good. My remaining hassle is that I can’t find the ()*&&$E#@_) CD I wrote the downloaded Outlook install stuff to and I doubt if MSFT is going to just want to flip me a replacement disk.

I’m kind of hoping to find a local friend who has it so that I can see if I can get it and ActiveSync (a POC program if ever there was one) to talk to my T-Mobile DASH phone / PDA. If I can, then I’ll drink the kool-aid and buy the software again.

BTW, since XP + MSIE7 trashed my file system, I’ve bought a 1T external drive. Cron and rsync are my new friends.

That’s a lot of spam :/

FYI, Ubuntu 8.04 warns you if your run “sudo rm -rf /”:
“rm: cannot remove root directory `/'”
… but says nothing to “sudo rm -rf /*” ^^

Hi,
I just experienced this. I copied the command from a blog (can’t remember where.)
Anyways, not only did it delete almost everything, it also traversed down the network, into my file server and also deleted a huge amount of file before I noticed it and stopped it.

What happened was it also deleted the .gvfs folder. Since the .gvfs folder also has pointers to any network folder that you’ve accessed, it also traversed those files. Problem is I generally access my network files using admin rights, so it just went to my .gvfs folder, to my network shares (with admin rights) and just started deleted everything. Luckily I have backups on a seperate pc.

It was really scary. Taught me a good lesson..

This comment has lots of spam comments: oyoy has posted a comment with an inappropriate word. Please clean up spam comments.

HAPPY FAMILY[VISIT PARENTALCARETEMPLE@GMAIL.COM],TO GET ADVICE AND SOLUTION TO ALL YOUR FAMILY PROBLEMS.
1; ARE YOUR HAVING PROBLEMS WITH YOUR RELATIONSHIP;
2; IS YOUR HUSBAND MESSING AROUND WITH OTHER GIRLS OUTSIDE,
3;ARE YOU FACING PROBLEMS WITH YOUR HUSBANDWIFE FAMILY[VISIT PARENTALCARETEMPLE@GMAIL.COM]
4;ARE YOU A MAN,YOU CAN’T FUNCTION WITH YOUR WIFE,YOU ARE TURNING YOUR WIFE INTO A SISTER
5;ARE YOU LOOKING FOR A CHILD[MALEFEMALE]
6;ARE YOU FACING PROBLEMS WITH YOUR PERIOD[VISIT PARENTALCARETEMPLE@GMAIL.COM]
7;IS YOU HUSBAND BEATING YOU OR TRYING TO DRIVE YOU OUT,
8;DO YOU WANT TO DIRECT YOUR HUSBAND EYE SEE ONLY YOU AS A WOMAN,
9;IN THIS TEMPLE,HIV CURE IS GUARANTEE
10;DO YOU WANT YOUR EX-BOYFRIENDHUSBAND BACK
11;DO YOU WANT TO NO YOUR SOULMATE[VISIT PARENTALCARETEMPLE@GMAIL.COM]
12;DO YOU ALWAY HAVE NIGHTMARESSPIRITHUSBAND
these are the area of specialization,if there is any request or complain VISIT [PARENTALCARETEMPLE@GMAIL.COM]THIS MESSAGE IS SENT TO ALL VIEWER’S WHO HAD SIMILAR PROBLEMS

EMAIL SMARTJOY@GMAIL.COM,FOR HER TESTIMONY[ AND THE KIND OF MIRACLES HAPPENLY IN THIS TEMPLE]

Hello………
my name is Mrs lawrenta pedro,i am from Manchester united,i am happily
married and blessed with kids,i am a business woman and my husband is
business man too we both operating provision store, on October 1st 2010 me
and my husband embank on a trip to South Africa,on our way back,we had a terrible
accident,that took my husband’s life,while i was rushed to the hospital,by
god grace,i was still living,after a year and seven month,when my husband
were passed away,a man came to my house,and ask me to get married to him,
unknown, that he was HIV positive and i never bordered to conduct a check
up test with him,before,i accepted him into my life,why,because,he was so
cute,gentle and handsome young man,he was so caring.i never look at
him,like one that would be hiv positive.after two year of our marriage,my
body system began to weak up,all day i feel dizzy and lazy,and i began to
lose weight as well,so i went for a check up test ,for
[fever,hiv/aid,malaria],the result, show me that, i am HIV positive.so i
was afraid,that,i would die,so,i were running from hospitals,churches and
native doctors,searching for cure, because i didn’t want to die.one day i
went to a pastor’s house,i told him my problem;as i was telling the pastor
my problem, there was one man which was with us,which i never look at his
face,the pastor prayed for me,on my way out , this same man,who was siting
with us,called me,i was like asking myself why this man was calling me, so
i just manage to wait to hear out what he will say,he told me that,he will
like to introduce me to this spell caster man, his name is HIOYA,SO
i JUST SAID thanks and leaved,i never wanted to go and see this man called HIOYA,but a mind,ask me to go for a try,so i went there,i meant him and i explain everything to him,he cast a spell on me and he told me,after two weeks,i should go for a hiv check up test again,after two weeks,i went for the hiv test,which the result shows me that i am now HIV NEGATIVE,whaoooooooo. i was like mad at the hospital,very happy…..if you have any problem you are facing now…..

HE IS SPECIALIZING IN THE FOLLOWING SPELL.
love spell
marriage spell
divorce spell
(1) If you want your ex back.
(2) If you always have bad dreams.
(3) If you want to be promoted in your office.
(4) If you want women/men to run after you.
(5) If you want a child.
(6) If you want to be rich.
(7) If you want to tie your husband/wife to be yours forever.
(8) If you need financial assistance.
(9) How you been scammed and you want to recover you lost money.
(10) If you want to stop your divorce.
(11) If you want to divorce your husband.
(12) If you want your wishes to be granted.
(13) Pregnancy spells to conceive baby
(14) Guarantee you win the troubling court cases & divorce no matter how what stage
(15) Stop your marriage or relationship from breaking apart.
(16) If you have any sickness like (H I V), (CANCER) or any sickness.
(17) If you need prayers for deliverance for your child or yourself.
(18)are having legs or joint pain,that is making you not to walk well
Once again make sure you contact him if you have any problem he will help you. contact him immediately via[ greathioyatemple@gmail.com]

Leave a Reply

Your email address will not be published. Required fields are marked *