Can someone explain to me what this command does?

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

sudo find / -exec rm {} \;
  • As you (originally) presented it,-exec rm {}\; will give a syntax error. The correct syntax requires a space between {} and \; – Peter.O Sep 3 '15 at 19:34
  • The command needs a \! -type d to not spew all those silly errors. – oals Sep 3 '15 at 19:46
  • 2
    @oals Or redirect errors to /dev/null. Also check the -delete option of find. – ott-- Sep 3 '15 at 19:56
  • 4
    I can't tell if this is a jokeā€¦ or if someone told you to do it as a "joke". – Shep Sep 4 '15 at 1:58
  • On a professionally maintained and secure system it should (probably) not do anything useful. – roaima Sep 4 '15 at 9:03

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.

| improve this answer | |
  • 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" :-) – Nate Eldredge Sep 3 '15 at 20:33
  • 4
    This avoids the built-in protection in GNU rm, which blatantly refuses to remove everything from the root downward. – Simon Richter Sep 4 '15 at 2:43
  • 2
    Note that this command won't be equivalent to sudo rm -rf /. Attempt to remove / is prohibit by POSIX rm (busybox rm does remove /). – cuonglm Sep 4 '15 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! – terdon Sep 4 '15 at 11:02

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.

| improve this answer | |
  • @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. – John Lyon Sep 4 '15 at 5:10
  • @jozzas: No, find / list all files and directories under /, all directories left unchange, only files removed. – cuonglm Sep 4 '15 at 6:41
  • @cuonglm I have already mentioned that..please check second paragraph.. – heemayl Sep 4 '15 at 8:41
  • @heemayl: Ah, I see, sorry for my mis-reading. – cuonglm Sep 4 '15 at 8:42

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

Don't run it!

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.