<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>chomd | 酷 壳 - CoolShell</title>
	<atom:link href="https://coolshell.cn/tag/chomd/feed" rel="self" type="application/rss+xml" />
	<link>https://coolshell.cn</link>
	<description>享受编程和技术所带来的快乐 - Coding Your Ambition</description>
	<lastBuildDate>Wed, 13 Oct 2010 01:17:53 +0000</lastBuildDate>
	<language>zh-CN</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.2</generator>
	<item>
		<title>chmod -x chmod的N种解法</title>
		<link>https://coolshell.cn/articles/3136.html</link>
					<comments>https://coolshell.cn/articles/3136.html#comments</comments>
		
		<dc:creator><![CDATA[陈皓]]></dc:creator>
		<pubDate>Wed, 13 Oct 2010 00:42:37 +0000</pubDate>
				<category><![CDATA[Unix/Linux]]></category>
		<category><![CDATA[杂项资源]]></category>
		<category><![CDATA[趣味问题]]></category>
		<category><![CDATA[轶事趣闻]]></category>
		<category><![CDATA[chomd]]></category>
		<category><![CDATA[cpio]]></category>
		<category><![CDATA[Emacs]]></category>
		<category><![CDATA[tar]]></category>
		<guid isPermaLink="false">http://coolshell.cn/?p=3136</guid>

					<description><![CDATA[<p>在SlidesShare.net上有这么一个幻灯片，其说了如下的一个面试题： 如果某天你的Unix/Linux系统上的chomd命令被某人去掉了x属性（执行属性...</p>
<p class="read-more"><a class="btn btn-default" href="https://coolshell.cn/articles/3136.html"> Read More<span class="screen-reader-text">  Read More</span></a></p>
The post <a href="https://coolshell.cn/articles/3136.html">chmod -x chmod的N种解法</a> first appeared on <a href="https://coolshell.cn">酷 壳 - CoolShell</a>.]]></description>
										<content:encoded><![CDATA[<p><script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-3415450859608158"
     crossorigin="anonymous"></script>在SlidesShare.net上有这么<a href="http://www.slideshare.net/cog/chmod-x-chmod" target="_blank">一个幻灯片</a>，其说了如下的一个面试题：</p>
<blockquote><p>如果某天你的Unix/Linux系统上的chomd命令被某人去掉了x属性（执行属性），<br />
那么，你如何恢复呢？</p></blockquote>
<p>下面是一些答案：</p>
<p><strong>1）重新安装</strong>。对于Debian的系统：</p>
<p><code data-enlighter-language="shell" class="EnlighterJSRAW">sudo apt-get install --reinstall coreutils</code></p>
<p><strong>2）使用语言级的chmod</strong>。</p>
<ul>
<li>Perl：perl-e &#8216;chmod 0755, &#8220;/bin/chmod&#8221;&#8216;</li>
<li>Python：python -c &#8220;import os;os.chmod(&#8216;/bin/chmod&#8217;, 0755)&#8221;</li>
<li>Node.js：require(&#8220;fs&#8221;).chmodSync(&#8220;/bin/chmod&#8221;, 0755);</li>
<li>C程序：</li>
</ul>
<pre data-enlighter-language="c" class="EnlighterJSRAW">#include &lt;sys/types.h&gt;
#include&lt;sys/stat.h&gt;
void main()
{
chmod(&quot;/bin/chmod&quot;, 0000755);
}</pre>
<p><span id="more-3136"></span></p>
<p><strong>3）使用已有的可执行文件。</strong></p>
<pre data-enlighter-language="shell" class="EnlighterJSRAW">
$cat - &gt; chmod.c
void main(){}
^D

$cc chmod.c
$cat /bin/chmod &gt; a.out
$./a.out 0755 /bin/chmod
</pre>
<pre data-enlighter-language="shell" class="EnlighterJSRAW">
$cp true &gt; new_chmod
$cat /bin/chmod &gt; new_chmod
$./new_chmod 0755 /bin/chmod
</pre>
<p><strong>4）使用GNU tar命令</strong></p>
<pre data-enlighter-language="shell" class="EnlighterJSRAW">$tar --mode 0755 -cf chmod.tar /bin/chmod
$tar xvf chmod.tar</pre>
<p><code data-enlighter-language="shell" class="EnlighterJSRAW">tar --mode 755 -cvf - chmod | tar -xvf -</code></p>
<p><strong>5）使用cpio</strong> （第19到24字节为file mode &#8211; <a href="http://4bxf.sl.pt" target="_blank">http://4bxf.sl.pt</a>）</p>
<pre data-enlighter-language="shell" class="EnlighterJSRAW">
echo chmod |
cpio -o |
perl -pe &#039;s/^(.{21}).../${1}755/&#039; |
cpio -i -u</pre>
<p><strong>6）使用hardcore</strong></p>
<p><code data-enlighter-language="shell" class="EnlighterJSRAW">alias chmod=&#039;/lib/ld-2.11.1.so ./chmod&#039;</code></p>
<p><strong>7）使用Emacs</strong></p>
<blockquote><p>Ctrl+x b &gt; * scratch*<br />
(set-file-modes &#8220;/bin/chmod&#8221; (string-to-number &#8220;0755&#8221; 8))<br />
Ctrl+j</p></blockquote>
<p>嗯，挺强大的，不过为什么不用install命令呢？</p>
<pre data-enlighter-language="shell" class="EnlighterJSRAW">install -m 755 /bin/chmod /tmp/chmod
mv /tmp/chmod /bin/chmod</pre>
<p>各位，你的方法呢？</p>
<p>（全文完）<!--



<p align="center"><a href= target=_blank><img decoding="async" src=""></a></p>





<p align="center"><img decoding="async" src="https://coolshell.cn/wp-content/uploads/2020/03/coolshell.weixin.jpg"> <img decoding="async" loading="lazy" src="https://coolshell.cn/wp-content/uploads/2020/03/coolshell.mini_.jpg" width="300" height="300"> <br />关注CoolShell微信公众账号和微信小程序</p>

 

--></p>
<div style="margin-top: 15px; font-size: 16px;color: #cc0000;">
<p align="center"><strong>（转载本站文章请注明作者和出处 <a href="https://coolshell.cn/">酷 壳 &#8211; CoolShell</a> ，请勿用于任何商业用途）</strong></p>
</div>

<div class="wp_rp_wrap  wp_rp_vertical_m" id="wp_rp_first"><div class="wp_rp_content"><h3 class="related_post_title">相关文章</h3><ul class="related_post wp_rp"><li ><a href="https://coolshell.cn/articles/3437.html" class="wp_rp_thumbnail"><img src="https://coolshell.cn/wp-content/uploads/2010/12/ediff-small-150x150.png" alt="一些杂项资源" width="150" height="150" /></a><a href="https://coolshell.cn/articles/3437.html" class="wp_rp_title">一些杂项资源</a></li><li ><a href="https://coolshell.cn/articles/3125.html" class="wp_rp_thumbnail"><img src="https://coolshell.cn/wp-content/uploads/2010/10/horrorstories.txt-150x150.jpg" alt="主流文本编辑器学习曲线" width="150" height="150" /></a><a href="https://coolshell.cn/articles/3125.html" class="wp_rp_title">主流文本编辑器学习曲线</a></li><li ><a href="https://coolshell.cn/articles/2271.html" class="wp_rp_thumbnail"><img src="https://coolshell.cn/wp-content/uploads/2010/03/emacs_color_theme-150x150.jpg" alt="Emacs配色在线生成器" width="150" height="150" /></a><a href="https://coolshell.cn/articles/2271.html" class="wp_rp_title">Emacs配色在线生成器</a></li><li ><a href="https://coolshell.cn/articles/1640.html" class="wp_rp_thumbnail"><img src="https://coolshell.cn/wp-content/plugins/wordpress-23-related-posts-plugin/static/thumbs/15.jpg" alt="文件备份的几个简单命令" width="150" height="150" /></a><a href="https://coolshell.cn/articles/1640.html" class="wp_rp_title">文件备份的几个简单命令</a></li><li ><a href="https://coolshell.cn/articles/2967.html" class="wp_rp_thumbnail"><img src="https://coolshell.cn/wp-content/plugins/wordpress-23-related-posts-plugin/static/thumbs/28.jpg" alt="代码优化概要" width="150" height="150" /></a><a href="https://coolshell.cn/articles/2967.html" class="wp_rp_title">代码优化概要</a></li><li ><a href="https://coolshell.cn/articles/17049.html" class="wp_rp_thumbnail"><img src="https://coolshell.cn/wp-content/uploads/2015/04/filter-150x150.png" alt="Docker基础技术：Linux CGroup" width="150" height="150" /></a><a href="https://coolshell.cn/articles/17049.html" class="wp_rp_title">Docker基础技术：Linux CGroup</a></li></ul></div></div>The post <a href="https://coolshell.cn/articles/3136.html">chmod -x chmod的N种解法</a> first appeared on <a href="https://coolshell.cn">酷 壳 - CoolShell</a>.]]></content:encoded>
					
					<wfw:commentRss>https://coolshell.cn/articles/3136.html/feed</wfw:commentRss>
			<slash:comments>22</slash:comments>
		
		
			</item>
	</channel>
</rss>
