-1

Warning:
To avoid catastrophic data loss, readers should NOT run this, nor any variations on it!

I would like to understand what does this command do: sudo rm -rf/*

Eliah Kagan
  • 117,780
Helen
  • 129
  • 1
  • 3
  • rm (remove files) -r (recursive) -f (force) /* (starting in / or root directory) ; the sudo elevates privileges. you can man rm to read the manual page for rm – guiverc Jun 24 '19 at 10:59
  • 2
    It deletes everything on your disk(s). Do not run this unless you want to destroy your installation and lose all files on your computer! – Byte Commander Jun 24 '19 at 11:01
  • 6
    It will give an error because of a typo. – xiota Jun 24 '19 at 11:05
  • @xiota Where is the typo? – Helen Jun 24 '19 at 11:08
  • 1
    @Helen the typo is that there should be a space between the -rf and /*. – Arronical Jun 24 '19 at 11:31
  • @xiota I disagree, warning people not to use a command is impossible without showing the actual command. – Arronical Jun 24 '19 at 11:31
  • 1
    Helen, every command on a ubuntu system has thorough documentation: see man sudo and man rm – glenn jackman Jun 24 '19 at 11:38
  • 1
    @Arronical The command didn't come out of nowhere. It's hard to believe OP did not know it is potentially dangerous. If OP is a newbie, it would have come from a list of commands known to be dangerous. If OP is not a newbie, then this could be an intentional attempt to get other people to run the command. – xiota Jun 24 '19 at 11:39
  • 1
    @xiota if OP is a newbie then some other person may be maliciously advising them to run this command, therefore letting them know it's dangerous would be a useful thing to do. There's a question on SE where somebody nuked their system because they took advice from somebody over IRC to rm -rf a lot of their binary storage locations, they wouldn't have done it if they'd known what the command did. – Arronical Jun 24 '19 at 11:52
  • 1
    @xiota yes there's zero context, so speculatively ascribing motivation to the OP is a bit pointless. There's a nice bold warning at the top of the post and it's been closed as a duplicate now, which seems the correct way for it to be handled. – Arronical Jun 24 '19 at 12:00
  • 1
    @xiota I edited again so directly copying from the title, or unthinkingly typing a stream of text from it, doesn't produce the situation you're describing. This lowers but doesn't eliminate the risk, which I think was low already. There are other older questions with comparable titles, whose OPs ran a "corrected" (i.e., much more dangerous) version of this or similar commands, sometimes to completion and sometimes not, and wanted help recovering data or reinstalling their systems. I would not retitle those. But this post is short and doesn't really benefit from a verbatim command in the title. – Eliah Kagan Jun 24 '19 at 12:23

2 Answers2

9
  • rm = remove files
  • -r = recursive
  • -f = force (ie. don't ask for confirmation)
  • The options were grouped as -rf to save typing.
  • /* = files to start removing; ie. start in / or root directory
  • sudo elevates privileges - so the user will have write permission to everything.

In summary, that command will delete every single file on your system without any sort of confirmation.

You can run man rm to read the manual page for rm.

guiverc
  • 30,396
  • 1
    As already stated; it's a command you should NOT try unless it's a VM or machine you are destroying.. – guiverc Jun 24 '19 at 11:06
  • 1
    This answer is incorrect. The command in the question has a typo that would prevent it from running as this answer indicates. – xiota Jun 24 '19 at 11:34
  • 1
    I chose to ignore the typo. I hoped it (typo) was made on purpose so idiots don't try it out, and chose not to correct that issue as it didn't impact what I was saying. – guiverc Jun 24 '19 at 12:27
7

As presented, the command will give an error because of a typo.

sudo rm -rf/*
[sudo] password for ___: 
rm: invalid option -- '/'
Try 'rm --help' for more information.

Without the typo, the command would attempt to delete all files on the system. It would throw errors for some files, which are inherently undeletable, such as some contained in /proc, /sys, /dev, or read-only file systems.

Although someone else has already indicated in comments how to correct it, I will not do so in this answer because it might cause some newbies to destroy their systems.

For more information about the rm command, see man rm.

xiota
  • 4,849