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.
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?
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.
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.
@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.
29 Comments
CallMeAl@piefed.zip · 17 pts · 57d
Surely you can tell us, Codewizard!
remon@ani.social · 8 pts · 57d
It will delete everything in the directory after that, without asking for further confirmation.
0xKesh@lemmy.dbzer0.com · 9 pts · 57d
Unless it's on /, where preserve-root should be kicking in, unless the bypass flag is used (can't remember this one)
Havatra@lemmy.zip · 7 pts · 57d
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.
0xKesh@lemmy.dbzer0.com · 1 pts · 57d
What distro was this out of curiosity? As far as I'm aware preserve-root enforcement comes from upstream coreutils
Havatra@lemmy.zip · 1 pts · 57d
Iirc, it was Debian 10 (Buster). I thought they enforced it (
rmdid support it at the time), but perhaps it was tricked by using an empty variable or something?0xKesh@lemmy.dbzer0.com · 2 pts · 57d
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
toynbee@piefed.social · 1 pts · 57d
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.
Successful_Try543@feddit.org · 3 pts · 57d
No, it does nothing.
If you dont specify the
-foption, which among other things tellsrmto be quiet, it throws an error:remon@ani.social · 1 pts · 57d
Because you're using it on nothing.
No more test folder.
Successful_Try543@feddit.org · 5 pts · 57d
Exactly, but that wasn't the question.
remon@ani.social · 2 pts · 57d
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).
Successful_Try543@feddit.org · 3 pts · 57d
The question is:
rm -rf *or hererm -rf testare different commands.remon@ani.social · 2 pts · 57d
rm is the command, -rf are the flags and "test" is an required argument. So no, they are not different commands.
Successful_Try543@feddit.org · 4 pts · 57d
No, the argument is not required, the command is valid. It's intentional and a neat feature that
rm -rfalone without a specified file does nothing.See e.g.: https://unix.stackexchange.com/a/553741
AstroLightz@lemmy.world · 8 pts · 57d
You have it backwards.
rm -fr /*removes the French language pack that comes preinstalled on your system./j
Zwuzelmaus@feddit.org · 5 pts · 57d
For even more fun, add a single / at the end.
/s
waldfee@feddit.org · 2 pts · 57d
You can have even more fun with
~neidu3@sh.itjust.works · 3 pts · 57d
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:
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-rootas well if you really wish to do so.Strider@lemmy.world · 2 pts · 57d
Creating a quick test vm isn't that hard, go nuts.
hedders@fedia.io · 1 pts · 45d
@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.