Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I noticed in the documentation for rm as obtained by rm --help the following flag:

--no-preserve-root  do not treat `/' specially

What does this mean? Is it actually possible to delete the root directory, apart from its contents? What consequences would that have?

share|improve this question
1  
Yes, they put in place a protection from people who try rm -rf /. They put that in place because yes, you can and you're system will be useless. –  nerdwaller Jan 28 '13 at 17:02
    
In my understanding, rm -rf / deletes the contents of the root directory; but wouldn't the root directory itself still exist? –  gerrit Jan 28 '13 at 17:03
    
@gerrit: Yes, it would. But this command is precisely why the "preserve root" mode was added: rm refuses to operate recursively on / unless you add the --no-preserve-root option. –  grawity Jan 28 '13 at 17:04

1 Answer 1

up vote 6 down vote accepted

You cannot delete the root directory itself. However, you can use rm's recursive mode to delete everything in that directory – the infamous rm -rf / command.

The "preserve root" mode stops rm from recursively operating on the root directory:

$ sudo rm -rf /
rm: it is dangerous to operate recursively on ‘/’
rm: use --no-preserve-root to override this failsafe

The --preserve-root option was added to GNU rm in 2003 (commit 9be74f6f125b2be), and was made the default behavior in 2006 (commit aff5a4f2ab86f).

Some say it is because pranksters in #ubuntu kept telling newbies to run rm -rf / – and many did. Some say it is because it is too easy to mistype rm -rf / tmp/junk. Some say it is to prevent accidents when running rm -rf $dir/ when $dir is empty. All we know is, he's called th

Solaris rm also has similar protection.

share|improve this answer
3  
Did you actually dare to type that for real? –  gerrit Jan 28 '13 at 17:05
1  
Linux is cheap, as are old computers. Admit that you've done it on a decommissioned system to see how to quickly create disk space. And the answer is yes. –  Fiasco Labs Jan 28 '13 at 17:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.