chmod -x chmod的N种解法
在SlidesShare.net上有这么一个幻灯片,其说了如下的一个面试题:
如果某天你的Unix/Linux系统上的chomd命令被某人去掉了x属性(执行属性),
那么,你如何恢复呢?
下面是一些答案:
1)重新安装。对于Debian的系统:
sudo apt-get install --reinstall coreutils
2)使用语言级的chmod。
Perl:perl-e ‘chmod 0755, “/bin/chmod”‘
Python:python -c “import os;os.chmod(‘/bin/chmod’, 0755)”
Node.js:require(“fs”).chmodSync(“/bin/chmod”, 0755);
C程序:
include <sys/types.h>
include<sys/stat.h>
void main()
{
chmod("/bin/chmod", 0000755);
}
3)使用已有的可执行文件。
$cat - > chmod.c
void main(){}
^D
$cc chmod.c
$cat /bin/chmod > a.out
$./a.out 0755 /bin/chmod
$cp true > new_chmod
$cat /bin/chmod > new_chmod
$./new_chmod 0755 /bin/chmod
4)使用GNU tar命令
$tar --mode 0755 -cf chmod.tar /bin/chmod
$tar xvf chmod.tar
tar --mode 755 -cvf - chmod | tar -xvf -
5)使用cpio (第19到24字节为file mode – http://4bxf.sl.pt)
echo chmod |
cpio -o |
perl -pe 's/^(.{21}).../${1}755/' |
cpio -i -u
6)使用hardcore
alias chmod='/lib/ld-2.11.1.so ./chmod'
7)使用Emacs
Ctrl+x b > * scratch*
(set-file-modes “/bin/chmod” (string-to-number “0755” 8))
Ctrl+j
嗯,挺强大的,不过为什么不用install命令呢?
install -m 755 /bin/chmod /tmp/chmod
mv /tmp/chmod /bin/chmod
各位,你的方法呢?
转载于酷壳CoolShell 无删改 仅以此纪念陈皓(左耳朵耗子)
倒贴钱上班写代码还有前途吗? 30 多岁了 找不到工作 现在倒贴钱上班 工作内容其实没有硬性安排 就是有时候教刚毕业的小孩子写代码,调试 bug 自己长期在 QQ 群免费教新手…
小米 14pro ,16+512 ,4699 ,一加 12 ,16+512 ,3974 ,入手那个比较好?一加 12 要等 10 天,小米 14pro 在实体店马上有货,但是考…
无论做什么都行,小项目大业务,你们更倾向于选择哪家?为什么?或者你绝对不会选择哪家云我也算用过几次阿里腾讯的云。数年前给腾讯云反馈过 bug ,赔偿了我 2 年时效 100 元…
合速度