7

Can someone explain to me what this command does?

EDIT: Do not run this command! It will break your installation.

sudo find / -exec rm {} \;
8
  • As you (originally) presented it,-exec rm {}\; will give a syntax error. The correct syntax requires a space between {} and \; Commented Sep 3, 2015 at 19:34
  • The command needs a \! -type d to not spew all those silly errors. Commented Sep 3, 2015 at 19:46
  • 2
    @oals Or redirect errors to /dev/null. Also check the -delete option of find. Commented Sep 3, 2015 at 19:56
  • 5
    I can't tell if this is a joke… or if someone told you to do it as a "joke". Commented Sep 4, 2015 at 1:58
  • 1
    man find tends to have answers for things related to find... Commented Sep 4, 2015 at 20:18

3 Answers 3

27

Bad Things ® ™. It's (almost) the equivalent of sudo rm -rf / - it will, as root, find all files or directories starting from / and recursively descending from there, and then execute the rm command against each file/directory it finds. It won't actually delete directory entries as there's no -f or -r options passed to rm, but it will remove all the file entries.

Hint: don't run this unless you feel like reinstalling your operating system.

4
  • 11
    Strictly speaking, at some point it will delete /bin/rm, and after that it will fail to delete any more files. The suggestion by @ott to use -delete would fix this "bug" :-) Commented Sep 3, 2015 at 20:33
  • 4
    This avoids the built-in protection in GNU rm, which blatantly refuses to remove everything from the root downward. Commented Sep 4, 2015 at 2:43
  • 3
    Note that this command won't be equivalent to sudo rm -rf /. Attempt to remove / is prohibit by POSIX rm (busybox rm does remove /). Commented Sep 4, 2015 at 8:55
  • As Cuonglm said, sudo rm -rf / is harmless on POSIX (and most other) systems, so no, this is not like it at all! Commented Sep 4, 2015 at 11:02
9

Don't run it.

This will find everything (all files, directories, links, sockets etc) under / i.e. everything in the system and then it will try to remove those one at a time with rm.

Note that as there is no -r option with rm, only the directory entries will not be removed, everything else will be gone.

4
  • @cuonglm find / will list all files, and -exec executes the command on each result of find. So it's the find command doing the recursion, and rm is only called for each individual file. Commented Sep 4, 2015 at 5:10
  • @jozzas: No, find / list all files and directories under /, all directories left unchange, only files removed. Commented Sep 4, 2015 at 6:41
  • @cuonglm I have already mentioned that..please check second paragraph.. Commented Sep 4, 2015 at 8:41
  • @heemayl: Ah, I see, sorry for my mis-reading. Commented Sep 4, 2015 at 8:42
3

Simple! This command will remove all files in your server.

Don't run it!

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.