<?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>东东有礼 &#187; gzip</title>
	<atom:link href="http://leedd.com/tag/gzip/feed/" rel="self" type="application/rss+xml" />
	<link>http://leedd.com</link>
	<description>东东有礼的互联网观察</description>
	<lastBuildDate>Thu, 10 May 2012 16:11:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Linux下创建与解压tar, tar.gz和tar.bz2文件及压缩率对比</title>
		<link>http://leedd.com/2010/01/linux-tar-tar-gz-tar-bz2/</link>
		<comments>http://leedd.com/2010/01/linux-tar-tar-gz-tar-bz2/#comments</comments>
		<pubDate>Mon, 18 Jan 2010 09:26:23 +0000</pubDate>
		<dc:creator>东东有礼</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[学习笔记]]></category>
		<category><![CDATA[gzip]]></category>
		<category><![CDATA[tar]]></category>
		<category><![CDATA[tar.bz2]]></category>
		<category><![CDATA[tar.gz]]></category>
		<category><![CDATA[tgz]]></category>
		<category><![CDATA[zip]]></category>

		<guid isPermaLink="false">http://leedd.com/?p=808</guid>
		<description><![CDATA[Linux下创建与解压zip, tar, tar.gz和tar.bz2文件及该文件压缩对比
 刚在qq群里面一位仁兄问到文件压缩的...]]></description>
			<content:encoded><![CDATA[<p><!-- 		@page { margin: 2cm } 		P { margin-bottom: 0.21cm } 		H2 { margin-bottom: 0.21cm } 		H2.western { font-family: "Liberation Serif", serif } 		H2.cjk { font-family: "方正宋体"; font-style: normal } 		H2.ctl { font-family: "方正宋体" } --></p>
<h2><span style="font-family: Liberation Serif,serif;">Linux</span>下创建与解压<span style="font-family: Liberation Serif,serif;">zip, tar, tar.gz</span>和<span style="font-family: Liberation Serif,serif;">tar.bz2</span>文件及该文件压缩对比</h2>
<p><span style="font-family: Liberation Serif,serif;"> </span>刚在<span style="font-family: Liberation Serif,serif;">qq</span>群里面一位仁兄问到文件压缩的命令，平时工作中大多用解压缩命令，要是遇到压缩就现查（这不是一个好习惯），于是整理下<span style="font-family: Liberation Serif,serif;">Linux</span>下创建与解压<span style="font-family: Liberation Serif,serif;">zip</span>、<span style="font-family: Liberation Serif,serif;">tar</span>、<span style="font-family: Liberation Serif,serif;">tar.gz</span>和<span style="font-family: Liberation Serif,serif;">tar.bz2</span>文件及他们之间压缩率对比，在自己的脑袋内存空间有限又不经常使用的时候以便于备忘。现整理如下：</p>
<p><strong><span style="font-family: Liberation Serif,serif;"> </span>目前<span style="font-family: Liberation Serif,serif;">Linux</span>下常见的压缩文件扩展名：</strong></p>
<pre><span style="font-family: Liberation Serif,serif;"> <strong>*.Z        compress</strong></span><strong>程序压缩的文件（最早期使用）<span style="font-family: Liberation Serif,serif;">,</span>压缩后取代源文件；
<span style="font-family: Liberation Serif,serif;"> *.zip      </span>一个夸平台的文件打包程序，适用于<span style="font-family: Liberation Serif,serif;">Linux</span>、<span style="font-family: Liberation Serif,serif;">windows</span>和<span style="font-family: Liberation Serif,serif;">Mac OS</span>系统；
<span style="font-family: Liberation Serif,serif;"> *.bz2      bzip2</span>程序压缩的文件；
<span style="font-family: Liberation Serif,serif;"> *.gz       gzip</span>程序压缩的文件；
<span style="font-family: Liberation Serif,serif;"> *.tar      tar</span>程序打包的文件，并没有压缩；
<span style="font-family: Liberation Serif,serif;"> *.tar.gz   tar</span>程序打包的文件，并经过<span style="font-family: Liberation Serif,serif;">gzip</span>程序的压缩；
<span style="font-family: Liberation Serif,serif;"> *.tar.bz2  tar</span>程序打包的文件，并经过<span style="font-family: Liberation Serif,serif;">bzip2</span>程序压缩。</strong><!-- 		@page { margin: 2cm } 		P { margin-bottom: 0.21cm } --></pre>
<p><span style="font-family: Liberation Serif,serif;"><span style="color: #0000ff;"> </span><span style="color: #0000ff;"><span style="font-size: medium;"><strong>Tips</strong></span></span></span><span style="color: #0000ff;"><span style="font-size: medium;"><strong>：</strong></span></span>所谓扩展名只是大家约定的通用格式，是为了更方便的能一眼识别出是什么压缩类型，当然你可以打包或压缩为任意格式的后缀名，只要你愿意。</p>
<p><span id="more-808"></span></p>
<p><strong><span style="font-family: Liberation Serif,serif;"> A</span></strong><strong>）<span style="font-family: Liberation Serif,serif;">*.zip</span>格式是大家最常见的一种，它具有夸操作系统平台性，可以同时在<span style="font-family: Liberation Serif,serif;">windows</span>、<span style="font-family: Liberation Serif,serif;">Linux</span>和<span style="font-family: Liberation Serif,serif;">Mac Os</span>上使用。</strong></p>
<p><span style="font-family: Liberation Serif,serif;"> </span>大家可以用<span style="font-family: Liberation Serif,serif;">zip</span>格式压缩那些需要共享给<span style="font-family: Liberation Serif,serif;">windows</span>用户的文件。压缩与解压<span style="font-family: Liberation Serif,serif;"><strong>.ZIP</strong></span>格式的文件：</p>
<pre><span style="font-family: Liberation Serif,serif;">[Lee@leedd.Com tmp]$ <strong>zip -r test.zip tmp</strong> </span>
<span style="font-family: Liberation Serif,serif;">adding: test/ (stored 0%) </span>
<span style="font-family: Liberation Serif,serif;">adding: test/data-file (deflated 24%) </span>
<span style="font-family: Liberation Serif,serif;">adding: test/r (deflated 51%) </span></pre>
<p>下面是如果解压一个<span style="font-family: Liberation Serif,serif;">zip</span>文档：</p>
<pre><span style="font-family: Liberation Serif,serif;">[Lee@leedd.Com tmp]$ <strong>rm -rf test </strong>	#</span>为测试解压，先删除当前目录下的<span style="font-family: Liberation Serif,serif;">tmp</span>文件
<span style="font-family: Liberation Serif,serif;">[Lee@leedd.Com tmp]$ <strong>unzip  test.zip</strong> </span>
Archive:  test.zip
  creating: test/
 inflating: test/data-file
 inflating: test/r</pre>
<p><strong><span style="font-family: Liberation Serif,serif;">B) </span>压缩与解压<span style="font-family: Liberation Serif,serif;">*.tar*</span>、<span style="font-family: Liberation Serif,serif;">.tar.gz</span>、<span style="font-family: Liberation Serif,serif;">*.tar.bz2 </span>格式的文件及对比：</strong><span style="font-family: Liberation Serif,serif;"><br />
Tar</span>是在<span style="font-family: Liberation Serif,serif;">Linux</span>中使用得非常广泛的文档打包格式。它的好处就是它只消耗非常少的<span style="font-family: Liberation Serif,serif;">CPU</span>以及时间去打包文件，他仅仅只是一个打包工具，并不负责压缩<span style="font-family: Liberation Serif,serif;">,</span>压缩是由<span style="font-family: Liberation Serif,serif;">gzip</span>与<span style="font-family: Liberation Serif,serif;">bzip2</span>来实现的。因此把<span style="font-family: Liberation Serif,serif;"><strong>*.tar*</strong></span>、<span style="font-family: Liberation Serif,serif;"><strong>.tar.gz</strong></span>、<span style="font-family: Liberation Serif,serif;"><strong>*.tar.bz2 </strong></span>放到一起来举例：</p>
<p>比如我们要把目录<span style="font-family: Liberation Serif,serif;"><strong>/var/tmp</strong></span>下的<span style="font-family: Liberation Serif,serif;"><strong>test</strong></span>目录<strong>打包压缩</strong>到当前目录</p>
<pre><span style="font-family: Liberation Serif,serif;">[Lee@leedd tmp]$ <strong>tar -cvf   test.tar   test                ### </strong></span>仅打包，不压缩
<span style="font-family: Liberation Serif,serif;">[Lee@leedd tmp]$ <strong>tar -zcvf  test.tar.gz    test        ### </strong></span>打包后以<span style="font-family: Liberation Serif,serif;"><strong>gzip</strong></span>压缩
<span style="font-family: Liberation Serif,serif;">[Lee@leedd tmp]$ <strong>tar -jcvf  test.tar.bz2   test        ### </strong></span>打包后以<span style="font-family: Liberation Serif,serif;"><strong>bzip2</strong></span>压缩
<span style="font-family: Liberation Serif,serif;">[Lee@leedd tmp]$<strong> ll 	test.tar* 	                   ### </strong></span>对比压缩后<strong>文件大小</strong>
<span style="font-family: Liberation Serif,serif;">-rw-r--r-- 1 Lee mock 10240 01-18 17:05 test.tar </span>
<span style="font-family: Liberation Serif,serif;">-rw-r--r-- 1 Lee mock   357 01-18 17:06 test.tar.bz2 </span>
<span style="font-family: Liberation Serif,serif;">-rw-r--r-- 1 Lee mock   327 01-18 17:05 test.tar.gz</span></pre>
<p><strong>如何解压缩包：</strong></p>
<pre><span style="font-family: Liberation Serif,serif;">[Lee@leedd tmp]$ <strong>tar -xvf   test.tar</strong> </span>
<span style="font-family: Liberation Serif,serif;">[Lee@leedd tmp]$ <strong>tar -xvf   test.tar.gz</strong></span>
<span style="font-family: Liberation Serif,serif;">[Lee@leedd tmp]$ <strong>tar  -jxvf  test.tar.bz2</strong></span></pre>
<p>上面测试中，每次要删除解压后的<span style="font-family: Liberation Serif,serif;">test</span>文件后解压打其他目录，因为如果不定义解压后目录路径和名字则默认解压到当前目录并以把压缩包名称作为文件夹名字。如果要解压到其他目录（如<span style="font-family: Liberation Serif,serif;">:/var/tmp/find</span>）则如下：</p>
<pre><span style="font-family: Liberation Serif,serif;">[Lee@leedd tmp]$<strong> tar  -jxvf  test.tar.bz2  -C  /var/tmp/find </strong></span></pre>
<p><strong>关于</strong><span style="font-family: Liberation Serif,serif;"><strong>tar.gz</strong></span><strong>和</strong><span style="font-family: Liberation Serif,serif;"><strong>tar.bz2</strong></span><strong>压缩率的问题：</strong></p>
<p><span style="font-family: Liberation Serif,serif;"><strong> *.tar.gz </strong></span>在压缩时不会占用太多<span style="font-family: Liberation Serif,serif;">CPU</span>的，而且可以得到一个非常理想的压缩率。也会被简写成<span style="font-family: Liberation Serif,serif;">tgz</span>。</p>
<p><span style="font-family: Liberation Serif,serif;"><strong> *.tar.bz2</strong></span>网上好的资料说这种压缩格式是压缩率最好的、它比前面的方式要占用更多的<span style="font-family: Liberation Serif,serif;">CPU</span>与时间。但是经过上面的试验显示发现<span style="font-family: Liberation Serif,serif;">test.tar.gz</span>的大小竟然比<span style="font-family: Liberation Serif,serif;">test.tar.bz2</span>的更小（这是否意味者<span style="font-family: Liberation Serif,serif;">*.tar.gz</span>拥有更小的压缩率？ 至少这次实验是这样）</p>
<pre><strong><span style="font-family: Liberation Serif,serif;"> </span>如下附上这次测验的文件包（点击文件名下载）：</strong>
<strong>Test文件夹中的2个文件： <a href="http://leedd.com/docs/linux/20100118/test/data-file">data-file</a>  和  <a href="http://leedd.com/docs/linux/20100118/test/r">r</a>
<a href="http://leedd.com/docs/linux/20100118/test.tar">test.tar</a>     <a href="http://leedd.com/docs/linux/20100118/test.tar.gz">test.tar.gz</a>        <a href="http://leedd.com/docs/linux/20100118/test.tar.bz2">test.tar.bz2</a></strong><a href="http://leedd.com/docs/linux/20100118/test.tar.bz2"><span style="font-family: Liberation Serif,serif;"> </span></a></pre>
]]></content:encoded>
			<wfw:commentRss>http://leedd.com/2010/01/linux-tar-tar-gz-tar-bz2/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

