Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 /?

share|improve this question
up vote 17 down vote accepted

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.

share|improve this answer
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 – Ulrich Dangel Mar 14 '13 at 14:38
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. – Stéphane Gimenez Mar 14 '13 at 14:38
@UlrichDangel, I found out the hard way on Solaris a long time back... – vonbrand Mar 14 '13 at 17:39
It will. You actually need to use rm --no-preserve-root / for this to actually work – Max Mar 14 '13 at 19:03
"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 '13 at 12:29

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

share|improve this answer

Your Answer


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.