15

Here's part of this xkcd comic strip where the idea is that the author can't write a sort program so he adds code to delete all files

system("rm -rf ./");
system("rm -rf ~/*");
system("rm -rf /");

AFAIK the canonical way to delete everything is to rm / so that everything starting from root is deleted. Here this is the last command and the two commands before that try to rm the current directory and the contents of the home directory.

Why not just rm /?

2 Answers 2

20

If you start at the very top, it's possible that you'll wipe out something that rm (or some other critical part of the system) needs to continue, and the evilness will be left incomplete.

These commands will make sure that at least the cwd and the user's home directory are gone before going nuclear.

7
  • 5
    JFTR as rm is loaded in the memor it should work and keep working even if necessary variables are removed. After you run rm -rf / from an interactive session your shell should be still working Mar 14, 2013 at 14:38
  • 8
    Recent rms will fail on the last command with rm: it is dangerous to operate recursively on ‘/’; other than that rm doesn't require access to any resource after initialization. A reason for using multiple commands might be that the user might have different access permissions to those directories. Mar 14, 2013 at 14:38
  • @UlrichDangel, I found out the hard way on Solaris a long time back...
    – vonbrand
    Mar 14, 2013 at 17:39
  • 1
    It will. You actually need to use rm --no-preserve-root / for this to actually work
    – Max
    Mar 14, 2013 at 19:03
  • 1
    "These commands will make sure that at least the cwd and the user's home directory are gone before going nuclear." What if we run that script when we are in "/bin/" :) ? Last two commands will not run at all.
    – XzKto
    Apr 10, 2013 at 12:29
8

Just to show increasing levels of destructiveness: Delete the current directory, then $HOME, finally destroy all.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .