-14
22

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

7h 8m ago by hear-me.social/ap/users/116280023545064493 in nostupidquestions

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

Surely you can tell us, Codewizard!

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

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

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.

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.

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.

Exactly, but that wasn't the question.

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).

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.

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

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

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.

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

Sure. And you should start learning basic bash skills.

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?

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.

Watching this back and forth while I’m eating my chips 😅

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

Generally a good idea to leave out the "-f" (so it would just be rm -r something). That way you'll get feedback when you're about to do something wrong or stupid!

rm -rf

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

/s

You have it backwards.

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

/j

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