<?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>tar | 酷 壳 - CoolShell</title>
	<atom:link href="https://coolshell.cn/tag/tar/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>
		<item>
		<title>文件备份的几个简单命令</title>
		<link>https://coolshell.cn/articles/1640.html</link>
					<comments>https://coolshell.cn/articles/1640.html#comments</comments>
		
		<dc:creator><![CDATA[陈皓]]></dc:creator>
		<pubDate>Fri, 30 Oct 2009 07:16:20 +0000</pubDate>
				<category><![CDATA[杂项资源]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[ftp]]></category>
		<category><![CDATA[tar]]></category>
		<category><![CDATA[wget]]></category>
		<category><![CDATA[zip]]></category>
		<guid isPermaLink="false">http://coolshell.cn/?p=1640</guid>

					<description><![CDATA[<p>我们知道，备份文件是一件很重要的事情，我在《优秀程序员的十个习惯》一文向大家说明了备份文件应该是程序员最基本的一个习惯。本文主要是向大家介绍一些在备份文件和数据...</p>
<p class="read-more"><a class="btn btn-default" href="https://coolshell.cn/articles/1640.html"> Read More<span class="screen-reader-text">  Read More</span></a></p>
The post <a href="https://coolshell.cn/articles/1640.html">文件备份的几个简单命令</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>我们知道，备份文件是一件很重要的事情，我在《<a rel="bookmark" href="https://coolshell.cn/articles/222.html">优秀程序员的十个习惯</a>》一文向大家说明了备份文件应该是程序员最基本的一个习惯。本文主要是向大家介绍一些在备份文件和数据时能用得到的一些示例，当然，这些示例主要是通过一些命令行或是脚本来实现的。这就是用命令行和脚本的优势，你可以实现比较灵活和自动的定制。</p>
<p>本文中的脚本和示例都是主要是通过zip, tar, ftp, wget和shell脚本来完成。在Linux下，你可以什么也不用安装任何程序，但在Windows下，你需要安装zip 和wget这三个命令（在本文的最后有这三个命令的链接，你可以去下载）</p>
<h4>几个小脚本</h4>
<p><strong>1）首先，我们来看一下，如何给某目录打个zip包。</strong></p>
<p><strong>Windows</strong>:</p>
<p><code data-enlighter-language="shell" class="EnlighterJSRAW"> zip -r backup.zip &quot;c:\yourfolder&quot;</code></p>
<p><strong>Linux</strong>: (打包自己的home目录)</p>
<p><code data-enlighter-language="shell" class="EnlighterJSRAW">tar -czvf ~/backup.tgz --exclude backup.tgz ~/</code></p>
<p><span id="more-1640"></span><br />
<strong>2）接下来，我们再来看一下，创建一个带有时间文件名的压缩包，并上传到远程主机的一个例子。</strong></p>
<p> <strong>Windows</strong></p>
<pre data-enlighter-language="shell" class="EnlighterJSRAW">
  :: cmd 脚本
  :: 压缩包文件格式`backup-mm-dd-yyyy.zip&#039;
  :: 注意：%dir% 被引号括起是怕目录名中有空格

  @echo off

  set host=ftp.yourhost.com
  set user=username
  set pass=password
  set file=backup-%date:~4,2%-%date:~7,2%-%date:~10%.zip
  set dir=&quot;yourfolder&quot;

  zip -r %file% %dir%

  &gt;  script.ftp echo open %host%
  &gt;&gt; script.ftp echo %user%
  &gt;&gt; script.ftp echo %pass%
  &gt;&gt; script.ftp echo bin
  &gt;&gt; script.ftp echo put %file%
  &gt;&gt; script.ftp echo bye

  ftp.exe -d -s:script.ftp &gt; backup.log

  del script.ftp
</pre>
<p><strong>Linux</strong></p>
<pre data-enlighter-language="shell" class="EnlighterJSRAW">
  #!/bin/bash

  host=&quot;ftp.yoursite.com&quot;
  user=&quot;username&quot;
  pass=&quot;password&quot;
  file=&quot;backup-$(date &#039;+%m-%d-%Y&#039;).tgz&quot;
  dir=&quot;$HOME&quot;

  tar -cvzf $file $dir

  ftp -vin &lt;ftp.log
  open $host
  user $user $pass
  bin
  put $file
  close
  bye
  EOF
</pre>
<p><strong>3）最后，我们来看一看，通过wget命令来下载备份好的压缩包。</strong></p>
<p><strong>Windows</strong></p>
<pre data-enlighter-language="shell" class="EnlighterJSRAW">
  :: cmd 脚本
  :: 注意： &#039;^&#039; 是一个命令的换行符

  set host=&quot;ftp://ftp.your.host.com&quot;
  set user=&quot;flintstone&quot;
  set pass=&quot;yabbadabbadoo&quot;

  wget %host% --ftp-user=%user% --ftp-password=%pass% ^ 
      --mirror --output-file=backup.log --passive-ftp
</pre>
<p><strong>Linux</strong></p>
<pre data-enlighter-language="shell" class="EnlighterJSRAW">
  #!/bin/sh
  # 注意 &#039;\&#039; 是命令的换行符
  
  host=&quot;ftp://ftp.your.host.com&quot;
  user=&quot;username&quot;
  pass=&quot;password&quot;

  wget $host --ftp-user=$user --ftp-password=$pass \
  --mirror --output-file=backup.log --passive-ftp
</pre>
<h4>相关工具</h4>
<ul>
<li>Info-Zip: <a href="http://www.info-zip.org/">http://www.info-zip.org/</a></li>
<li>GNU Tar: <a href="http://www.gnu.org/software/tar/">http://www.gnu.org/software/tar/</a></li>
<li>GNU Wget: <a href="http://www.gnu.org/software/wget/">http://www.gnu.org/software/wget/</a></li>
</ul>
<h4>几点注意</h4>
<p>上面的那几个命令比较简单，只是表明一些备份的脚本思路。在实际过程当中，基本上也是这样，下面是几点注意。</p>
<p>1）给备份文件打包压缩这是第一步，你可以选用其它的压缩程序。如bzip。<br />
2）文件名上有时间信息比较容易归档。有时候，文件包比较大，还需要对大文件进行分割（一般的压缩软件都支持文件分割）。<br />
3）使用wget和ftp可能会有用户名密码泄露的问题，使用ssh拷贝文件会比较好。<br />
4）源代码最好还是使用版本控制工具备份（比如Subversion或CVS）<br />
5）备份脚本可以放在计划任务（linux是corn）中以实际自动化。<br />
6）以上的方法一般说来比较适用于全部备份，而不是增量备份。</p>
<p>（全文完）<a href="http://topcat.hypermart.net/backup.html" target="_blank"></a><!--



<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" ><div class="wp_rp_content"><h3 class="related_post_title">相关文章</h3><ul class="related_post wp_rp"><li ><a href="https://coolshell.cn/articles/3136.html" class="wp_rp_thumbnail"><img src="https://coolshell.cn/wp-content/plugins/wordpress-23-related-posts-plugin/static/thumbs/3.jpg" alt="chmod -x chmod的N种解法" width="150" height="150" /></a><a href="https://coolshell.cn/articles/3136.html" class="wp_rp_title">chmod -x chmod的N种解法</a></li><li ><a href="https://coolshell.cn/articles/21214.html" class="wp_rp_thumbnail"><img src="https://coolshell.cn/wp-content/uploads/2020/12/go.pair_-150x150.png" alt="Go编程模式：委托和反转控制" width="150" height="150" /></a><a href="https://coolshell.cn/articles/21214.html" class="wp_rp_title">Go编程模式：委托和反转控制</a></li><li ><a href="https://coolshell.cn/articles/21146.html" class="wp_rp_thumbnail"><img src="https://coolshell.cn/wp-content/uploads/2020/12/go.options-150x150.png" alt="Go 编程模式：Functional Options" width="150" height="150" /></a><a href="https://coolshell.cn/articles/21146.html" class="wp_rp_title">Go 编程模式：Functional Options</a></li><li ><a href="https://coolshell.cn/articles/5966.html" class="wp_rp_thumbnail"><img src="https://coolshell.cn/wp-content/plugins/wordpress-23-related-posts-plugin/static/thumbs/16.jpg" alt="腾讯帐号申诉的用户体验" width="150" height="150" /></a><a href="https://coolshell.cn/articles/5966.html" class="wp_rp_title">腾讯帐号申诉的用户体验</a></li><li ><a href="https://coolshell.cn/articles/4811.html" class="wp_rp_thumbnail"><img src="https://coolshell.cn/wp-content/plugins/wordpress-23-related-posts-plugin/static/thumbs/0.jpg" alt="软件真的好难做啊" width="150" height="150" /></a><a href="https://coolshell.cn/articles/4811.html" class="wp_rp_title">软件真的好难做啊</a></li><li ><a href="https://coolshell.cn/articles/265.html" class="wp_rp_thumbnail"><img src="https://coolshell.cn/wp-content/plugins/wordpress-23-related-posts-plugin/static/thumbs/29.jpg" alt="深入浅出单实例Singleton设计模式" width="150" height="150" /></a><a href="https://coolshell.cn/articles/265.html" class="wp_rp_title">深入浅出单实例Singleton设计模式</a></li></ul></div></div>The post <a href="https://coolshell.cn/articles/1640.html">文件备份的几个简单命令</a> first appeared on <a href="https://coolshell.cn">酷 壳 - CoolShell</a>.]]></content:encoded>
					
					<wfw:commentRss>https://coolshell.cn/articles/1640.html/feed</wfw:commentRss>
			<slash:comments>6</slash:comments>
		
		
			</item>
	</channel>
</rss>
