{"id":2166,"date":"2012-10-19T09:59:25","date_gmt":"2012-10-19T01:59:25","guid":{"rendered":"https:\/\/kyle.ai\/blog\/?p=2166"},"modified":"2012-10-19T10:14:27","modified_gmt":"2012-10-19T02:14:27","slug":"linux%e5%8e%8b%e7%bc%a9%e6%96%87%e4%bb%b6%e7%9a%84%e5%91%bd%e4%bb%a4%e6%80%bb%e7%bb%93","status":"publish","type":"post","link":"https:\/\/kyle.ai\/blog\/2166.html","title":{"rendered":"Linux\u538b\u7f29\u6587\u4ef6\u7684\u547d\u4ee4\u603b\u7ed3"},"content":{"rendered":"<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n    *.Z       compress \u7a0b\u5e8f\u538b\u7f29\u7684\u6863\u6848\uff1b\r\n    *.bz2     bzip2 \u7a0b\u5e8f\u538b\u7f29\u7684\u6863\u6848\uff1b\r\n    *.gz      gzip \u7a0b\u5e8f\u538b\u7f29\u7684\u6863\u6848\uff1b\r\n    *.tar     tar \u7a0b\u5e8f\u6253\u5305\u7684\u6570\u636e\uff0c\u5e76\u6ca1\u6709\u538b\u7f29\u8fc7\uff1b\r\n    *.tar.gz  tar \u7a0b\u5e8f\u6253\u5305\u7684\u6863\u6848\uff0c\u5176\u4e2d\u5e76\u4e14\u7ecf\u8fc7 gzip \u7684\u538b\u7f29\uff01\r\n    *.zip     zip \u7a0b\u5e8f\u538b\u7f29\u6587\u4ef6\r\n    *.rar     rar \u7a0b\u5e8f\u538b\u7f29\u6587\u4ef6\r\n<\/pre>\n<p><span style=\"color: #ff0000;\">Compress\u538b\u7f29\u6587\u4ef6<\/span><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n&#x5B;root@test \/root]$ cp \/etc\/man.config \/root\r\n&#x5B;root@test \/root]$ compress man.config\r\n#\u538b\u7f29man.config\u8fd9\u4e2a\u6587\u4ef6\r\n\r\n&#x5B;root@test \/root]$ compress -d man.config.Z\r\n#-d \u89e3\u538b\u7f29\u8fd9\u4e2a\u6587\u4ef6\r\n\r\n&#x5B;root@test \/root]$ uncompress man.config.Z\r\n#\u89e3\u538b\u7f29\u8fd9\u4e2a\u6587\u4ef6\r\n<\/pre>\n<p>\u5f53\u4f60\u4ee5 compress \u538b\u7f29\u4e4b\u540e\uff0c\u5982\u679c\u6ca1\u6709\u4e0b\u8fbe\u5176\u5b83\u7684\u53c2\u6570\uff0c\u90a3\u4e48\u539f\u672c\u7684\u6863\u6848\u5c31\u4f1a\u88ab\u540e\u6765\u7684 *.Z \u6240\u53d6\u4ee3\uff01<br \/>\n<span style=\"color: #ff0000;\">Gzip\u538b\u7f29\u6587\u4ef6\u548czcat<\/span><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n&#x5B;root@test \/root]$ gzip &#x5B;-d#] filename\r\n#\u538b\u7f29\u4e0e\u89e3\u538b\u7f29\r\n\r\n&#x5B;root@test \/root]$ zcat filename.gz\r\n#\u8bfb\u53d6\u538b\u7f29\u6863\u5185\u5bb9\r\n<\/pre>\n<p>\u53c2\u6570\u8bf4\u660e\uff1a<br \/>\n-d \uff1a\u89e3\u538b\u7f29\u7684\u53c2\u6570\uff01<br \/>\n-r \uff1a\u9012\u5f52\u5904\u7406\uff0c\u5c06\u6307\u5b9a\u76ee\u5f55\u4e0b\u7684\u6240\u6709\u6587\u4ef6\u53ca\u5b50\u76ee\u5f55\u4e00\u5e76\u5904\u7406<br \/>\n-# \uff1a\u538b\u7f29\u7b49\u7ea7\uff0c 1 \u6700\u4e0d\u597d\uff0c 9 \u6700\u597d\uff0c 6 \u662f\u9ed8\u8ba4\u503c\uff01<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n&#x5B;root@test \/root]$ gzip man.config\r\n#\u4f1a\u4ea7\u751f man.config.gz \u8fd9\u4e2a\u6863\u6848\r\n\r\n&#x5B;root@test \/root]$ zcat man.config.gz\r\n#\u4f1a\u8bfb\u53d6\u51fa man.config \u7684\u5185\u5bb9\r\n\r\n&#x5B;root@test \/root]$ gzip -d man.config.gz\r\n&#x5B;root@test \/root]$ gunzip man.config.gz\r\n<\/pre>\n<p>\u89e3\u538b\u7f29\uff0c\u4ea7\u751f man.config \u8fd9\u4e2a\u6863\u6848<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n&#x5B;root@test \/root]$ gzip -9 man.config\r\n#\u4ee5\u6700\u5927\u538b\u7f29\u6bd4\u538b\u7f29 testing \u8fd9\u4e2a\u6863\u6848\uff01\r\n\r\n&#x5B;root@test \/root]$ gzip -r filename.gz file1 file2 file3 \/usr\/work\/school\r\n#file1\u3001file2\u3001 file3\u3001\u4ee5\u53ca \/usr\/work\/school \u76ee\u5f55\u7684\u5185\u5bb9\uff08\u5047\u8bbe\u8fd9\u4e2a\u76ee\u5f55\u5b58\u5728\uff09\u538b\u7f29\u8d77\u6765\uff0c\u7136\u540e\u653e\u5165 filename.bz2 \u6587\u4ef6\u4e2d\r\n<\/pre>\n<p><span style=\"color: #ff0000;\">Bzip2\u538b\u7f29\u6587\u4ef6\u548cbzcat<\/span><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n&#x5B;root@test \/root]$ bzip2 &#x5B;-dz] filename\r\n#\u538b\u7f29\u89e3\u538b\u7f29\u6307\u4ee4\r\n\r\n&#x5B;root@test \/root]$ bzcat filename.bz2\r\n#\u8bfb\u53d6\u538b\u7f29\u6587\u4ef6\u5185\u5bb9\u6307\u4ee4\r\n<\/pre>\n<p>\u53c2\u6570\u8bf4\u660e\uff1a<br \/>\n-d \uff1a\u89e3\u538b\u7f29\u7684\u610f\u601d\uff01<br \/>\n-z \uff1a\u538b\u7f29\u7684\u610f\u601d\uff01<br \/>\n\u8303\u4f8b\uff1a<br \/>\n\u540c\u6837\u7684\uff0c\u6211\u4eec\u4ee5\u521a\u521a\u62f7\u8d1d\u8fc7\u6765\u7684 \/root\/man.config \u8fd9\u4e2a\u6863\u6848\u4e3a\u4f8b<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n&#x5B;root@test \/root]$ bzip2 \u2013z man.config\r\n&#x5B;root@test \/root]$ bzcat man.config.bz2\r\n&#x5B;root@test \/root]$ bzip2 \u2013d man.config.bz2\r\n&#x5B;root@test \/root]$ bunzip2 man.config.bz2\r\n&#x5B;root@test \/root]$ bzip2 filename.bz2 file1 file2 file3 \/usr\/work\/school\r\n#file1\u3001file2\u3001 file3\u3001\u4ee5\u53ca \/usr\/work\/school \u76ee\u5f55\u7684\u5185\u5bb9\uff08\u5047\u8bbe\u8fd9\u4e2a\u76ee\u5f55\u5b58\u5728\uff09\u538b\u7f29\u8d77\u6765\uff0c\u7136\u540e\u653e\u5165 filename.bz2 \u6587\u4ef6\u4e2d\r\n<\/pre>\n<p><span style=\"color: #ff0000;\">Tar\u538b\u7f29\u6587\u4ef6<\/span><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n&#x5B;root@test \/root]$ tar &#x5B;-zxcvfpP] filename\r\n&#x5B;root@test \/root]$ tar -N 'yyyy\/mm\/dd' \/path -zcvf target.tar.gz source\r\n<\/pre>\n<p>\u53c2\u6570\u8bf4\u660e\uff1a<br \/>\n-z \uff1a\u662f\u5426\u540c\u65f6\u5177\u6709 gzip \u7684\u5c5e\u6027\uff1f<br \/>\n-x \uff1a\u89e3\u5f00\u4e00\u4e2a\u538b\u7f29\u6863\u6848\u7684\u53c2\u6570\u6307\u4ee4\uff01<br \/>\n-t \uff1a\u67e5\u770b tarfile \u91cc\u9762\u7684\u6863\u6848\uff01<br \/>\n-c \uff1a\u5efa\u7acb\u4e00\u4e2a\u538b\u7f29\u6863\u6848\u7684\u53c2\u6570\u6307\u4ee4<br \/>\n-v \uff1a\u538b\u7f29\u7684\u8fc7\u7a0b\u4e2d\u663e\u793a\u6863\u6848\uff01<br \/>\n-f \uff1a\u4f7f\u7528\u6863\u540d\uff0c\u8bf7\u7559\u610f\uff0c\u5728 f \u4e4b\u540e\u8981\u7acb\u5373\u63a5\u6863\u540d\u5594\uff01\u4e0d\u8981\u518d\u52a0\u53c2\u6570\uff01<br \/>\n\u4f8b\u5982\u4f7f\u7528\u300e tar -zcvfP tfile sfile\u300f\u5c31\u662f\u9519\u8bef\u7684\u5199\u6cd5\uff0c\u8981\u5199\u6210<br \/>\n\u300e tar -zcvPf tfile sfile\u300f\u624d\u5bf9\u5594\uff01<br \/>\n-p \uff1a\u4f7f\u7528\u539f\u6863\u6848\u7684\u539f\u6765\u5c5e\u6027\uff08\u5c5e\u6027\u4e0d\u4f1a\u4f9d\u636e\u4f7f\u7528\u8005\u800c\u53d8\uff09<br \/>\n-P \uff1a\u53ef\u4ee5\u4f7f\u7528\u7edd\u5bf9\u8def\u5f84<br \/>\n-N \uff1a\u6bd4\u540e\u9762\u63a5\u7684\u65e5\u671f(yyyy\/mm\/dd)\u8fd8\u8981\u65b0\u7684\u624d\u4f1a\u88ab\u6253\u5305\u8fdb\u65b0\u5efa\u7684\u6863\u6848\u4e2d\uff01<br \/>\n&#8211;exclude FILE\uff1a\u5728\u538b\u7f29\u7684\u8fc7\u7a0b\u4e2d\uff0c\u4e0d\u8981\u5c06 FILE \u6253\u5305\uff01<br \/>\n\u8303\u4f8b\uff1a<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n&#x5B;root@test \/root]$ tar -cvf directory.tar directory\r\n#\u53ea\u5c06\u76ee\u5f55\u6574\u5408\u6253\u5305\u6210\u4e00\u4e2a\u6863\u6848\r\n\r\n&#x5B;root@test \/root]$ tar -zcvf directory.tar.gz directory\r\n#\u9664\u4e86\u5c06\u76ee\u5f55\u6253\u5305\u5916\uff0c\u540c\u65f6\u4ee5 gzip \u538b\u7f29\r\n\r\n&#x5B;root@test \/root]$ tar -zcvf filename.tar.gz  \/home\/test\/*\r\n#\u5c06 \/home\/test\/ \u8fd9\u4e2a\u76ee\u5f55\u4e0b\u7684\u6863\u6848\u5168\u90e8\u6253\u5305\u5e76\u538b\u7f29\u6210\u4e3a\u4e00\u4e2a filename.tar.gz \u7684\u6863\u6848\r\n\r\n&#x5B;root@test \/root]$ tar -jcvf \/tmp\/etc.tar.bz2 \/etc &#x5B;root@test \/root]$ tar -xvf  directory.tar\r\n#\u89e3 tar \u7684\u5c01\u5305\uff0c\u8bf7\u6ce8\u610f\uff0c\u7531\u4e8e\u6ca1\u6709 gzip (.tar \u800c\u975e .tar.gz) \u7684\u4f5c\u7528\uff0c\u6240\u4ee5\u53ea\u8981\u4f7f\u7528 \u2013xvf \u5373\u53ef\uff01\u4e0d\u9700\u8981\u52a0\u4e0a z \uff0c\u5426\u5219\u4f1a\u663e\u793a\u6709\u95ee\u9898\uff01\r\n\r\n&#x5B;root@test \/root]$ tar -zxvf directory.tar.gz\r\n#\u8fd9\u4e2a\u5c31\u662f\u6709\u52a0\u4e0a gzip \u7684\u538b\u7f29\u7684\u7ed3\u679c\uff01\u6240\u4ee5\u9700\u8981\u52a0\u4e0a \u2013z \u5466\uff01\r\n\r\n&#x5B;root@test \/root]$ tar \u2013ztvf directory.tar.gz\r\n#\u8fd9\u4e2a t \u53ef\u4ee5\u7528\u6765\u67e5\u770b tar \u91cc\u9762\u7684\u6863\u6848\u4fe1\u606f\u5462\uff01\u800c\u4e0d\u9700\u8981\u5c06\u4ed6\u89e3\u5f00\uff01\r\n\r\n&#x5B;root@test \/root]$ tar -zcvPf home.tar.gz \/home\r\n#\u5219\u5efa\u7acb\u8d77\u6765\u7684\u538b\u7f29\u6863\u5185\u6863\u6848\u4e3a\u7edd\u5bf9\u8def\u5f84\r\n#\u8bf7\u6ce8\u610f\uff0c\u4f7f\u7528\u8fd9\u4e2a P \u7684\u53c2\u6570\u65f6\uff0c\u4e0d\u8981\u5c06 P \u52a0\u5728 f \u540e\u9762\uff0c\u56e0\u4e3a f \u4e4b\u540e\u8981\u7acb\u5373\u63a5\u6863\u540d\u624d\u884c\u5594\uff01\r\n\r\n&#x5B;root@test \/root]$ tar -N '2002\/06\/25' -zcvf home.tar.gz \/home\r\n#\u4e0a\u9762\u662f\u8bf4 \u5728 \/home \u8fd9\u4e2a\u76ee\u5f55\u4e2d\uff0c\u6bd4 2002\/06\/25 \u65e5\u8fd8\u8981\u65b0\u7684\u6863\u6848\u624d\u4f1a\u88ab\u6253\u5305\u8fdb\u5165 home.tar.gz \u8fd9\u4e2a\u6863\u6848\u4e2d\uff01\r\n\r\n&#x5B;root@test \/root]$ tar -zcvf host.tar.gz \/ --exclude \/mnt --exclude \/proc\r\n#\u4e0a\u9762\u662f\u8bf4\uff0c\u5c06\u6839\u76ee\u5f55\u7684\u6240\u6709\u6570\u636e\u90fd\u6253\u5305\u8fdb host.tar.gz \u8fd9\u4e2a\u6863\u6848\u4e2d\uff0c\u4f46\u662f \/mnt \u53ca \/proc \u5219\u4e0d\u6253\u5305\uff01\r\n\r\n&#x5B;root@test \/root]$ tar -cvf - \/home | tar -xvf -\r\n#\u4e0a\u9762\u7684\u610f\u601d\u662f\u300e\u5c06 \/home \u6253\u5305\u4e4b\u540e\uff0c\u76f4\u63a5\u89e3\u538b\u7f29\u5728 \/root \u5e95\u4e0b\uff01\u300f\u563f\u563f\uff01\u4e0d\u9700\u8981\u518d\u5efa\u7acb\u4e00\u6b21\u4e2d\u95f4\u6863\u6848\uff01\u4e0d\u8fc7\uff0c\u4f7f\u7528\u4e0a\u9762\u7684\u8bed\u6cd5\u6700\u597d\u4f7f\u7528\u300e\u7edd\u5bf9\u8def\u5f84\u300f\uff0c\u6bd4\u8f83\u4e0d\u4f1a\u6709\u95ee\u9898\uff01\u8fd9\u4e2a\u65b9\u5f0f\u9002\u5408\u4e0d\u60f3\u8981\u5efa\u7acb\u4e2d\u95f4\u6863\u6848\u65f6\uff01\r\n<\/pre>\n<p><span style=\"color: #ff0000;\">Zip\u548cunzip\u538b\u7f29\u6587\u4ef6<\/span><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n&#x5B;root@test \/root]$ zip -r myfile.zip .\/*\r\n#\u5c06\u5f53\u524d\u76ee\u5f55\u4e0b\u7684\u6240\u6709\u6587\u4ef6\u548c\u6587\u4ef6\u5939\u5168\u90e8\u538b\u7f29\u6210myfile.zip\u6587\u4ef6,\uff0dr\u8868\u793a\u9012\u5f52\u538b\u7f29\u5b50\u76ee\u5f55\u4e0b\u6240\u6709\u6587\u4ef6.\r\n\r\n&#x5B;root@test \/root]$ zip -d myfile.zip smart.txt\r\n#\u5220\u9664\u538b\u7f29\u6587\u4ef6\u4e2dsmart.txt\u6587\u4ef6\r\n\r\n&#x5B;root@test \/root]$ zip -m myfile.zip .\/rpm_info.txt\r\n#\u5411\u538b\u7f29\u6587\u4ef6\u4e2dmyfile.zip\u4e2d\u6dfb\u52a0rpm_info.txt\u6587\u4ef6\r\n\r\n&#x5B;root@test \/root]$ unzip -o -d \/home\/sunny myfile.zip\r\n#\u628amyfile.zip\u6587\u4ef6\u89e3\u538b\u5230 \/home\/sunny\/\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>*.Z compress \u7a0b\u5e8f\u538b\u7f29\u7684\u6863\u6848\uff1b *.bz2 bzip2 \u7a0b\u5e8f\u538b\u7f29\u7684\u6863\u6848\uff1b *.gz gzip \u7a0b\u5e8f [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-2166","post","type-post","status-publish","format-standard","hentry","category-skill"],"_links":{"self":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/2166","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/comments?post=2166"}],"version-history":[{"count":6,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/2166\/revisions"}],"predecessor-version":[{"id":2172,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/2166\/revisions\/2172"}],"wp:attachment":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/media?parent=2166"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/categories?post=2166"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/tags?post=2166"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}