声明:该文章摘自陈皓的酷壳。

问题:

如果某天你的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", );
    }

3)使用已有的可执行文件。

$cat - > chmod.c
void main(){}
^D $cc chmod.c
$cat /bin/chmod > a.out
$./a.out /bin/chmod
$cp true > new_chmod
$cat /bin/chmod > new_chmod
$./new_chmod /bin/chmod

4)使用GNU tar命令

$tar --mode  -cf chmod.tar /bin/chmod
$tar xvf chmod.tar
tar --mode  -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 “″ ))
Ctrl+j

嗯,挺强大的,不过为什么不用install命令呢?

install -m  /bin/chmod /tmp/chmod
mv /tmp/chmod /bin/chmod

各位,你的方法呢?

(全文完)

chmod -x chmod的N种解法的更多相关文章

  1. [LeetCode] Remove Element (三种解法)

    Given an array and a value, remove all instances of that value in place and return the new length. T ...

  2. codewars.DNA题目几种解法分析(字符串替换)

    题干: 意思就是字符串替换,"A"与"C"配对,"T"与"G"配对,DNA不为空. 解法一:我的解法,用for循环遍历字 ...

  3. LeetCode算法题-Minimum Distance Between BST Nodes(Java实现-四种解法)

    这是悦乐书的第314次更新,第335篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第183题(顺位题号是783).给定具有根节点值的二叉搜索树(BST),返回树中任何两个 ...

  4. LeetCode算法题-Number Complement(Java实现-五种解法)

    这是悦乐书的第240次更新,第253篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第107题(顺位题号是476).给定正整数,输出其补码数.补充策略是翻转其二进制表示的位 ...

  5. LeetCode算法题-Third Maximum Number(Java实现-四种解法)

    这是悦乐书的第222次更新,第235篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第89题(顺位题号是414).给定非空的整数数组,返回此数组中的第三个最大数字.如果不存 ...

  6. LeetCode算法题-Longest Palindrome(五种解法)

    这是悦乐书的第220次更新,第232篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第87题(顺位题号是409).给定一个由小写或大写字母组成的字符串,找到可以用这些字母构 ...

  7. LeetCode算法题-Find the Difference(Java实现-五种解法)

    这是悦乐书的第214次更新,第227篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第82题(顺位题号是389).给定两个字符串s和t,它们只包含小写字母.字符串t由随机混 ...

  8. LeetCode算法题-Valid Perfect Square(Java实现-四种解法)

    这是悦乐书的第209次更新,第221篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第77题(顺位题号是367).给定正整数num,写一个函数,如果num是一个完美的正方形 ...

  9. LeetCode算法题-Intersection of Two Arrays(Java实现-四种解法)

    这是悦乐书的第207次更新,第219篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第75题(顺位题号是349).给定两个数组,编写一个函数来计算它们的交集.例如: 输入: ...

随机推荐

  1. dedecms 修改标题长度可以修改数据库

    数据表为dede__archives 字段为title 首先要在 a.系统->系统基本参数->其它选项->文章标题长度 b.系统->SQL命令行工具 alter table # ...

  2. 使用Raphael 画图(三) 事件 (javascript)

    这章展示事件例子. 下图是官方API的事件: 例子: var butt1 = paper.set(); var a1 = paper.circle(24.833, 26.917, 26.667).at ...

  3. js操作Cookie,实现历史浏览记录

    /** * history_teacher.jsp中的js,最近浏览名师 * @version: 1.0 * @author: mingming */ $(function(){ getHistory ...

  4. 如何在search中动态的显示和隐藏tree中的字段

    在tree定义 invisible 来自context <field name="country_id" invisible="context.get('invis ...

  5. Linux——搭建PHP开发环境第三步:mysql

    原文链接:http://www.jb51.net/article/83647.htm 1.第一步就是看linu是否安装了mysql,经过rpm -qa|grep mysql查看到centos下安装了m ...

  6. BZOJ 1037 生日聚会

    Description 今天是hidadz小朋友的生日,她邀请了许多朋友来参加她的生日party. hidadz带着朋友们来到花园中,打算坐成一排玩游戏.为了游戏不至于无聊,就座的方案应满足如下条件: ...

  7. codeforces C. k-Tree

    思路:dp[i][j]表示和为i,最大值为j的方案数. #include <cstdio> #include <cstring> #include <algorithm& ...

  8. 【HDOJ】1247 Hat’s Words

    字典树. #include <cstdio> #include <cstring> #include <cstdlib> #define MAXN 50005 #d ...

  9. 「Poetize8」Divisible

    描述 Description 设F[i]为斐波那契数列的第i项,F[1]=1,F[2]=1,F[i]=F[i-1]+F[i-2](i>=3). 输入格式 InputFormat 输入包含若干行( ...

  10. weblogic jsp 不生效解决方法

    1. 检查weblogic.xml配置文件,其中如果有: <jsp-descriptor> <jsp-param> <param-name>pageCheckSec ...