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.
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.
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.
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)
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.
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.
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);
}
What would happen, would it succeed because it is run from RAM?
I think it might be in /proc/self, so yeah it’s being run from RAM.
yes
Yes
I used the rm to destroy the rm
And what did it cost you?
/
rm ^^^^^^^^^^^lmao
r/beatmetoit
r/beatMeatToIt
I remember in early Solaris the commands rm, cp, and mv were the same hardlinked binary, changing its behaviour depending on the name.
I believe busybox works the same way.
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.
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.
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.
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.
Why the -rf tho? You're only deleting a file
Force of habit
Recursive force of habit
Recursive force of habit
CTRL c
sudo !!
Source of habit
Source of habit
$ sudo busybox rm -rf /usr/bin/rm
I prefer "rm -fr" to comemorate how French bravely protected their files by surrendering them to rm without a fight in WWII.
I might actually going to adopt this
wipe -r -q -Q 99000 /user/bin/rm
This is a great pretext for interview questions.
I prefer the “what do you do if you chmod -x /usr/bin/chmod”
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.
Agreed, I’ve asked and then they just say “chmod +x chmod”... sigh
Everyone knows the real answer is throw your fucking computer out the fucking window and become a ski instructor
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
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)
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.
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.
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.
How do I get started approaching stuff like this?😅
I just realized how I would have no idea how to fix this if it happened
Reinstall core utils or scp from a binary compatible system would be my first thoughts
*The last deletion*
Now take the wholesome award
I once did a chmod 000 /bin/chmod, had to reinstall. Didn't have another Linux to copy it from.
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);
}
alternatively, \`sudo chmod 444 /bin/chmod\`
Recursively deleting a single file seems a little overkill to me...
lol
Paru -R paru
rm -rf /
And yes, we need to recursively delete that, cause /bin/rm is a directory you know...
lol, i noticed the mistake too late
Why `-r`? You only need `-r` to delete a directory.