200
48
I've often wondered how far the system will actually get if you run rm -rf /
. I doubt the OS would be able to erase itself (?)
Bonus Question: After the command has been executed, will rm
have removed itself?
Update: I've tested this in a couple of the main unix distributions using VirtualBox and the answers describe exactly what happens. If given the correct parameters, rm will remove every physical bit of data on the disc. However, I ran into some issues when using a version of rm other than the GNU one. For example, I believe BusyBox has their own version and it doesn't let you remove as much as you potentially could.
This question was a Super User Question of the Week.
Read the July 7th, 2011 blog entry for more details or submit your own Question of the Week.
3I've just tried
sudo rm -rf /
on tinycore/microcore linux and it seems that the OS protects several directories (/sys and others) from being deleted. – n0pe – 2011-07-20T14:06:40.52047I tried
rm -f /bin/rm
once. Unfortunately, it worked, and I spent the next hour getting the right version ofrm
back from GNU coreutils. – squircle – 2011-07-20T17:21:32.36317Wait a sec, I will try... – Martijn Courteaux – 2011-07-20T18:16:24.127
This really depends on the operating system. Any non-Windows OS should support the command, but will inevitably handle it differently. I'd like to suggest to close this question as it is non-specific and nothing that can't be discovered for a particular OS with a virtual machine. – stimpy77 – 2011-07-20T18:31:03.630
8
It's funny that you asked this question. I was just answering another rm -f question on another forum and started remembering an article I read a while back. Luckily I saved it for times like this: THE classic Unix horror story Besides the fact that it's interesting to see how far it'll go... I think it's a very well written article and is a generally good read!
– akseli – 2011-07-20T13:57:50.480@stimpy77 Even variations in how the filesystem of a given machine (even running the same OS and version of rm) will affect the result of the command. For example, if the core utilities or common commands are mounted as a memory filesystem, only loaded from disk on boot? – None – 2011-07-20T22:30:44.317
Some guy had a post long ago about (
sudo
)rm -Rf *
on *nix vs.format c:
on a Windows box (quickly changed todel \f \s \q *
) – Nick T – 2011-07-21T01:40:53.68338I do this at the apple store all the time – eggie5 – 2011-07-21T05:40:50.140
2It will not remove every bit of physical data, especially if the disk in question is an SSD! It will only unlink every file and directory. – Blacklight Shining – 2013-10-22T12:41:42.767