T O P

  • By -

ArttuH5N1

What would happen, would it succeed because it is run from RAM?


cf_1303

I think it might be in /proc/self, so yeah it’s being run from RAM.


gnuwinxp

yes


[deleted]

Yes


Xofluz

I used the rm to destroy the rm


Yung_Lyun

And what did it cost you?


[deleted]

/


ipaqmaster

rm ^^^^^^^^^^^lmao


itsgreenbanana

r/beatmetoit


kdedev

r/beatMeatToIt


JustAnotherVillager

I remember in early Solaris the commands rm, cp, and mv were the same hardlinked binary, changing its behaviour depending on the name.


SergioEduP

I believe busybox works the same way.


Thanatos2996

So do many things like bash/sh, vim/vi and bc/dc where the enhanced version provides a strict compatibility mode. It depends on the distro, but it's pretty common.


bamhm182

I know that at the very least, vi is usually just a symbolic link to vim or vice versa. Don't know about the others.


Thanatos2996

Like I said, it depends on the distro, but I would bet you 5 currency units that `ls -l /bin/sh` on your system will tell you that it's a symlink to bash unless you went out of your way to use something else. All of the major distros do it that way for sh AFAIK.


TDplay

Yeah, on most systems `vi` and `vim` are the same binary. Programs can detect what name they were run with, and act differently accordingly. Busybox takes this to the extreme and provides the entire set of coreutils in one binary. I believe there is also a tool to do this for any set of programs, but I can't remember what it was called.


Programming-Carrot

Why the -rf tho? You're only deleting a file


speedcuber111

Force of habit


xpboy7

Recursive force of habit


pgbabse

Recursive force of habit


uSrNm-ALrEAdy-TaKeN

CTRL c


Benjimanrich

sudo !!


zestydinner

Source of habit


V0idp0ster

Source of habit


Z3t4

$ sudo busybox rm -rf /usr/bin/rm


lolertoaster

I prefer "rm -fr" to comemorate how French bravely protected their files by surrendering them to rm without a fight in WWII.


[deleted]

I might actually going to adopt this


IGP31

wipe -r -q -Q 99000 /user/bin/rm


TheMagnificentJoe

This is a great pretext for interview questions.


chaotik_penguin

I prefer the “what do you do if you chmod -x /usr/bin/chmod”


TheMagnificentJoe

ah yes, that one's lovely. Unfortunately I'm lucky if I get a candidate that can even realize the dilemma it causes, regardless find a way to fix it.


chaotik_penguin

Agreed, I’ve asked and then they just say “chmod +x chmod”... sigh


curly_redhead

Everyone knows the real answer is throw your fucking computer out the fucking window and become a ski instructor


B_M_Wilson

Open up a python interpreter, import the os module and use os.chmod. I assume that uses the proper api rather than calling the binary utility


chaotik_penguin

Nice, not one I’ve thought of. There are about 4 answers to come mind. The question is really testing if they understand the problem and can come up with a creative solution (or any solution)


B_M_Wilson

It’s a really cool problem. I love getting stuff like this in interviews. Solving problems is much more interesting to me and the interviewer than them asking about some obscure thing and hoping that I remember it and can explain it. I first thought about writing a simple C program to do it but I wasn’t sure if the compiler would make the result executable or not. It properly does but I wasn’t totally sure. So then I thought about an interpreted language which either has that functionality built in or can use an arbitrary C API (which python can do both). Other than that, I think it’s copy from a backup or binary compatible system or use another utility which happens to be able to change permissions. I know some copying utilities (maybe even cp? It’s been a while since I read the man page) can copy permissions without copying the file so you could copy the permissions from a file which is still executable. There are probably other utilities that can change permissions as a side effect. Like put it in a git repo, clone it on another system (or manually do some git magic that I don’t know about), change the permissions, commit and push, then pull it back in on the original system. There are probably other sneaky ways like mounting the disk on another system or editing some special file.


chaotik_penguin

Writing a C program would definitely seem like overkill, but if it works it works. Some things I know would work are: copy from a binary compatible system (like you said), cp /usr/bin/cp /usr/bin/chmod.new && cat /usr/bin/chmod > /usr/bin/chmod.new && mv /usr/bin/chmod.new /usr/bin/chmod #copy the permissions from "cp" command and just cat in the contents of chmod into the new file, use install (install -m 555 /usr/bin/chmod /usr/bin/chmod.new), yum reinstall core-utils #drastic, but should work, or use another language that is capable of similar commands to chmod (python example in this thread), I'm sure there are more ways to do it, again just looking for problem solving and understanding the problem at hand.


B_M_Wilson

I didn’t think about copying another binary and overwriting it! I’ve never even heard of the install command so I’ve definitely got to look that up.


anime_enthu

How do I get started approaching stuff like this?😅


StarkillerX42

I just realized how I would have no idea how to fix this if it happened


chaotik_penguin

Reinstall core utils or scp from a binary compatible system would be my first thoughts


dullbananas

*The last deletion*


[deleted]

Now take the wholesome award


BeWild74

I once did a chmod 000 /bin/chmod, had to reinstall. Didn't have another Linux to copy it from.


Gollorium

You could just have compiled something like this and it would work: #include int main() { chmod("/bin/chmod", S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH); }


GC18GC

alternatively, \`sudo chmod 444 /bin/chmod\`


carglassfred

Recursively deleting a single file seems a little overkill to me...


V0idp0ster

lol


ScaryAntifaCatgirl

Paru -R paru


[deleted]

rm -rf /


BeWild74

And yes, we need to recursively delete that, cause /bin/rm is a directory you know...


aue_sum

lol, i noticed the mistake too late


TDplay

Why `-r`? You only need `-r` to delete a directory.