Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

2 Answers 2

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
4  
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
7  
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
    
@StéphaneGimenez- Recent versions It will fail like that even with the -f flag? –  user606723 Mar 14 '13 at 18:22
    
It will. You actually need to use rm --no-preserve-root / for this to actually work –  Max Mar 14 '13 at 19:03

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

share|improve this answer

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.