@nostupidquestions what happens when you give the command in the command line rm -rf ?

all 12 comments

sorted by: hot top controversial new old
[–] 17 points 4 months ago

Surely you can tell us, Codewizard!

  • source
  • [–] 8 points 4 months ago (6 children)

    It will delete everything in the directory after that, without asking for further confirmation.

  • source
  • hideshow 6 child comments
  • [–] 9 points 4 months ago (5 children)

    Unless it's on /, where preserve-root should be kicking in, unless the bypass flag is used (can't remember this one)

  • source
  • parent
  • hideshow 5 child comments
  • [–] 7 points 4 months ago* (4 children)

    Not all systems have the preserve-root flag enforced, actually... I accidentally did the rm -rf / in a bash script (the variable for the path returned empty), and it irreversibly deleted a bunch of my system, including sudo and a big part of /etc, before I realized and did Ctrl+C. However the damage was done, rendering the system both unusable and unbootable. Fortunately I managed to recover some data, as the drive was not encrypted.

    Edit: Yes, like a fool I ran the script as sudo... I am now older and wiser.

  • source
  • parent
  • hideshow 4 child comments
  • [–] 1 point 4 months ago (2 children)

    What distro was this out of curiosity? As far as I'm aware preserve-root enforcement comes from upstream coreutils

  • source
  • parent
  • hideshow 2 child comments
  • [–] 1 point 4 months ago (1 child)

    Iirc, it was Debian 10 (Buster). I thought they enforced it (rm did support it at the time), but perhaps it was tricked by using an empty variable or something?

  • source
  • parent
  • hideshow 1 child comment
  • [–] 2 points 4 months ago

    Ahhh, I just re-read your comment, and yeah that would have been the case.

    I think another quick bypass without using the proper flag could be to use a wildcard (for example, rm -rf /*), I think that might work too maybe

  • source
  • parent
  • [–] 1 point 4 months ago

    I didn't personally do this one, but I once worked at a job where I was tasked with updating a kickstart file from RHEL6 to 7. I don't remember the details, but in the postscript, there was a variable that was set in 6 but not 7. That variable was then used in a command like rm -rf /${variable}.

    It took me a little while to figure out why every system imaged with that kickstart was emptying its own filesystem.

  • source
  • parent
  • [–] 7 points 4 months ago*

    You have it backwards.

    rm -fr /* removes the French language pack that comes preinstalled on your system.

    /j

  • source
  • [–] 3 points 4 months ago*

    Short answer: Nothing

    Long answer: It is part of a command that deletes everything. The only thing missing is the argument specifying what to delete. Examples:

    rm -rf *
    rm -rf /some/directory
    

    It's somewhat (in)famous because it'll do so without asking for confirmation. The only exception is rm -rf / on a modern distro which will complain that you're attempting to delete EVERYTHING on the system. In the olden days it'd just do it, but these days it tells you to add --no-preserve-root as well if you really wish to do so.

  • source
  • [–] 2 points 4 months ago

    Creating a quick test vm isn't that hard, go nuts.

  • source
  • [–] 1 point 4 months ago

    @codewizard@hear-me.social Of itself, nothing - it needs another argument telling it what to perform the operation on. Something like rm -rf * would delete everything in the current directory and all subdirectories.

  • source