rm -rf /

… does not work. At least not today on a Debian/Sid system. Looks like there are some things, not even root is allowed to do:


root@sid:~# rm -rf /
rm: cannot remove root directory ‘/'

If you’re curious what happens when you wipe your disk on a running system:


root@sid:~# cd /
root@sid:/# rm -rf *

does the trick.

Update: That’s with plain rm not safe-rm.

Update 2: I looked through the code of rm.c to find that / is protected by default — as a simple rm --help also shows:

$ rm --help
Usage: rm [OPTION]… FILE…
Remove (unlink) the FILE(s).

[...]

–no-preserve-root do not treat `/’ specially
–preserve-root do not remove `/’ (default)

Tags:

6 Responses to “rm -rf /”

  1. lubos Says:

    you have instaled safe-rm, don’t you?

  2. plavy Says:

    No, no la hagas tio. Siempre hay motivo para vivir…

  3. James Says:

    Solaris managed to get rm -rf / prohibited as POSIX compliance, under the euphemism “pre-determined heuristic“.

  4. cate Says:

    It is the correct behaviour.

    Compare “rm -rf /tmp/” and “rm -rf /tmp/*”. The first one will remove also the directory, the second one no.

    Now think about removing “/” (will it last only ” “?). The root directory is special in the kernel: it is the root of the file tree. Allowing the root removal, the root must become a NULL pointer, thus requiring a lot of additional checks, which is not worth in POSIX like environment (Note: posix permit not allowing to remove some systems directory and files).

  5. youam Says:

    man rm:

    –no-preserve-root
    do not treat ‘/’ specially

    –preserve-root
    do not remove ‘/’ (default)

  6. giulivo navigante Says:

    this preserve option seems to me just a fucking stupid idea

Leave a Reply