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

all 29 comments

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

Surely you can tell us, Codewizard!

  • source
  • [–] 8 points 2 months ago*

    You have it backwards.

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

    /j

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

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

  • source
  • hideshow 4 child comments
  • [–] 9 points 2 months ago (1 child)

    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 2 child comments
  • [–] 7 points 2 months ago* (2 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 2 months ago (1 child)

    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 2 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 2 child comments
  • [–] 2 points 2 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 2 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
  • [–] 3 points 2 months ago* (1 child)

    No, it does nothing.

    $ mkdir test
    $ cd test
    ~/test$ touch 1 2 3 4 5
    ~/test$ rm -rf
    ~/test$ ls
    1  2  3  4  5
    

    If you dont specify the -f option, which among other things tells rm to be quiet, it throws an error:

    $ rm -r
    rm: missing operand
    Try 'rm --help' for more information.
    
  • source
  • parent
  • hideshow 2 child comments
  • [–] 1 point 2 months ago* (1 child)

    Because you're using it on nothing.

    $ mkdir test
    $ cd test
    ~/test$ touch 1 2 3 4 5
    ~/test$ cd ..
    $ rm -rf test
    $ ls
    

    No more test folder.

  • source
  • parent
  • hideshow 2 child comments
  • [–] 5 points 2 months ago* (last edited 2 months ago) (1 child)

    Exactly, but that wasn't the question.

  • source
  • parent
  • hideshow 2 child comments
  • [–] 2 points 2 months ago* (1 child)

    What are you talking about? The does exactly what I said it does.

    It only does nothing for you because you used it incorrectly (in the wrong folder without the required argument).

  • source
  • parent
  • hideshow 2 child comments
  • [–] 3 points 2 months ago (1 child)

    The question is:

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

    rm -rf * or here rm -rf test are different commands.

  • source
  • parent
  • hideshow 2 child comments
  • [–] 2 points 2 months ago* (1 child)

    rm is the command, -rf are the flags and "test" is an required argument. So no, they are not different commands.

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

    No, the argument is not required, the command is valid. It's intentional and a neat feature that rm -rf alone without a specified file does nothing.

    See e.g.: https://unix.stackexchange.com/a/553741

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

    It does nothing because you used the wrong syntax but also set the flag that suppresses the output of syntax errors ...

    Imagine someone would asked "What does a toaster do?"

    I say "It toasts bread".

    You come in with a picture of bread in a toaster and say "It does nothing".

    I tell you "You have to press the button".

    "You say "oh well, that wasn't the question, a toaster with the button pressed is basically a different device!"

    Insert <Futurama not sure if trolling ...> meme.

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

    You should obviously improve your reading skills.

    The File argument is optional.

    rm [OPTION]... [FILE]...

    https://www.man7.org/linux/man-pages/man1/rm.1.html

  • source
  • parent
  • hideshow 2 child comments
  • [–] -1 points 2 months ago (1 child)

    Sure. And you should start learning basic bash skills.

  • source
  • parent
  • hideshow 2 child comments
  • [–] 7 points 2 months ago (1 child)

    Alright, I've read both of you guys' arguments. You're both right, but you're both talking about different things.

    Successful try is responding with a literal direct computer-like response for OP's question. They are adding no additional qualifiers to the specific exact question that was asked, which is to say that the answer to OP's question is, it does nothing.

    Reman, you were saying that anybody who was trying to use this command would obviously add a subject, would put the test or something else to it, would make an adjustment to the command in order to make it work and actually function.

    And that is correct in practice, but that doesn't answer the question that was being asked literally. It answers the question the way a senior programmer would answer the question of a junior programmer.

    Successful try's answer is the answer a computer would give.

    So can you both please stop fucking arguing, hug it out, and move on?

  • source
  • parent
  • hideshow 2 child comments
  • [–] 2 points 2 months ago (2 children)

    Successful try’s answer is the answer a computer would give.

    I enjoy giving overly pedantic and technically correct answers as much as the next guy, but doing it on !nostupidquestions@lemmy.world seems like a dick move.

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

    @remon @bizarroland thanks a lot for enlightening me, and also showing me how exactly to use that particular command without breaking anything.

  • source
  • parent
  • hideshow 2 child comments
  • [–] 5 points 2 months ago (1 child)

    rm -rf

    For even more fun, add a single / at the end.

    /s

  • source
  • hideshow 2 child comments
  • [–] 3 points 2 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 2 months ago

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

  • source
  • [–] 1 point 2 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