mirror of
https://github.com/jaywcjlove/reference.git
synced 2025-06-18 05:01:21 +08:00
395 lines
29 KiB
HTML
395 lines
29 KiB
HTML
<!doctype html>
|
||
<html lang="en" data-color-mode="dark">
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<title>tar 备忘清单
|
||
& tar cheatsheet & Quick Reference</title>
|
||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||
<meta description="这是 tar 常用命令的快速参考备忘单。
|
||
|
||
入门,为开发人员分享快速参考备忘单。">
|
||
<meta keywords="tar,reference,Quick,Reference,cheatsheet,cheat,sheet">
|
||
<link rel="icon" href="data:image/svg+xml,%3Csvg%20viewBox%3D%220%200%2024%2024%22%20fill%3D%22none%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20height%3D%221em%22%20width%3D%221em%22%3E%20%3Cpath%20d%3D%22m21.66%2010.44-.98%204.18c-.84%203.61-2.5%205.07-5.62%204.77-.5-.04-1.04-.13-1.62-.27l-1.68-.4c-4.17-.99-5.46-3.05-4.48-7.23l.98-4.19c.2-.85.44-1.59.74-2.2%201.17-2.42%203.16-3.07%206.5-2.28l1.67.39c4.19.98%205.47%203.05%204.49%207.23Z%22%20fill%3D%22%23c9d1d9%22%2F%3E%20%3Cpath%20d%3D%22M15.06%2019.39c-.62.42-1.4.77-2.35%201.08l-1.58.52c-3.97%201.28-6.06.21-7.35-3.76L2.5%2013.28c-1.28-3.97-.22-6.07%203.75-7.35l1.58-.52c.41-.13.8-.24%201.17-.31-.3.61-.54%201.35-.74%202.2l-.98%204.19c-.98%204.18.31%206.24%204.48%207.23l1.68.4c.58.14%201.12.23%201.62.27Zm2.43-8.88c-.06%200-.12-.01-.19-.02l-4.85-1.23a.75.75%200%200%201%20.37-1.45l4.85%201.23a.748.748%200%200%201-.18%201.47Z%22%20fill%3D%22%23228e6c%22%20%2F%3E%20%3Cpath%20d%3D%22M14.56%2013.89c-.06%200-.12-.01-.19-.02l-2.91-.74a.75.75%200%200%201%20.37-1.45l2.91.74c.4.1.64.51.54.91-.08.34-.38.56-.72.56Z%22%20fill%3D%22%23228e6c%22%20%2F%3E%20%3C%2Fsvg%3E" type="image/svg+xml">
|
||
<link rel="stylesheet" href="../style/style.css">
|
||
<link rel="stylesheet" href="../style/katex.css">
|
||
</head>
|
||
<body><nav class="header-nav"><div class="max-container"><a href="../index.html" class="logo"><svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" height="1em" width="1em">
|
||
<path d="m21.66 10.44-.98 4.18c-.84 3.61-2.5 5.07-5.62 4.77-.5-.04-1.04-.13-1.62-.27l-1.68-.4c-4.17-.99-5.46-3.05-4.48-7.23l.98-4.19c.2-.85.44-1.59.74-2.2 1.17-2.42 3.16-3.07 6.5-2.28l1.67.39c4.19.98 5.47 3.05 4.49 7.23Z" fill="#c9d1d9"></path>
|
||
<path d="M15.06 19.39c-.62.42-1.4.77-2.35 1.08l-1.58.52c-3.97 1.28-6.06.21-7.35-3.76L2.5 13.28c-1.28-3.97-.22-6.07 3.75-7.35l1.58-.52c.41-.13.8-.24 1.17-.31-.3.61-.54 1.35-.74 2.2l-.98 4.19c-.98 4.18.31 6.24 4.48 7.23l1.68.4c.58.14 1.12.23 1.62.27Zm2.43-8.88c-.06 0-.12-.01-.19-.02l-4.85-1.23a.75.75 0 0 1 .37-1.45l4.85 1.23a.748.748 0 0 1-.18 1.47Z" fill="#228e6c"></path>
|
||
<path d="M14.56 13.89c-.06 0-.12-.01-.19-.02l-2.91-.74a.75.75 0 0 1 .37-1.45l2.91.74c.4.1.64.51.54.91-.08.34-.38.56-.72.56Z" fill="#228e6c"></path>
|
||
</svg>
|
||
<span class="title">Quick Reference</span></a><div class="menu"><a href="javascript:void(0);" class="searchbtn" id="searchbtn"><svg xmlns="http://www.w3.org/2000/svg" height="1em" width="1em" viewBox="0 0 18 18">
|
||
<path fill="currentColor" d="M17.71,16.29 L14.31,12.9 C15.4069846,11.5024547 16.0022094,9.77665502 16,8 C16,3.581722 12.418278,0 8,0 C3.581722,0 0,3.581722 0,8 C0,12.418278 3.581722,16 8,16 C9.77665502,16.0022094 11.5024547,15.4069846 12.9,14.31 L16.29,17.71 C16.4777666,17.8993127 16.7333625,18.0057983 17,18.0057983 C17.2666375,18.0057983 17.5222334,17.8993127 17.71,17.71 C17.8993127,17.5222334 18.0057983,17.2666375 18.0057983,17 C18.0057983,16.7333625 17.8993127,16.4777666 17.71,16.29 Z M2,8 C2,4.6862915 4.6862915,2 8,2 C11.3137085,2 14,4.6862915 14,8 C14,11.3137085 11.3137085,14 8,14 C4.6862915,14 2,11.3137085 2,8 Z"></path>
|
||
</svg><span>搜索</span><span>⌘K</span></a><a href="https://github.com/jaywcjlove/reference/blob/main/docs/tar.md" class="" target="__blank"><svg viewBox="0 0 36 36" fill="currentColor" height="1em" width="1em"><path d="m33 6.4-3.7-3.7a1.71 1.71 0 0 0-2.36 0L23.65 6H6a2 2 0 0 0-2 2v22a2 2 0 0 0 2 2h22a2 2 0 0 0 2-2V11.76l3-3a1.67 1.67 0 0 0 0-2.36ZM18.83 20.13l-4.19.93 1-4.15 9.55-9.57 3.23 3.23ZM29.5 9.43 26.27 6.2l1.85-1.85 3.23 3.23Z"></path><path fill="none" d="M0 0h36v36H0z"></path></svg><span>编辑</span></a><button id="darkMode" type="button"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="light" height="1em" width="1em">
|
||
<path d="M6.995 12c0 2.761 2.246 5.007 5.007 5.007s5.007-2.246 5.007-5.007-2.246-5.007-5.007-5.007S6.995 9.239 6.995 12zM11 19h2v3h-2zm0-17h2v3h-2zm-9 9h3v2H2zm17 0h3v2h-3zM5.637 19.778l-1.414-1.414 2.121-2.121 1.414 1.414zM16.242 6.344l2.122-2.122 1.414 1.414-2.122 2.122zM6.344 7.759 4.223 5.637l1.415-1.414 2.12 2.122zm13.434 10.605-1.414 1.414-2.122-2.122 1.414-1.414z"></path>
|
||
</svg>
|
||
<svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 24 24" class="dark" height="1em" width="1em">
|
||
<path d="M12 11.807A9.002 9.002 0 0 1 10.049 2a9.942 9.942 0 0 0-5.12 2.735c-3.905 3.905-3.905 10.237 0 14.142 3.906 3.906 10.237 3.905 14.143 0a9.946 9.946 0 0 0 2.735-5.119A9.003 9.003 0 0 1 12 11.807z"></path>
|
||
</svg>
|
||
</button><script src="../js/dark.js?v=1.3.6"></script><a href="https://github.com/jaywcjlove/reference" class="" target="__blank"><svg viewBox="0 0 16 16" fill="currentColor" height="1em" width="1em"><path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.012 8.012 0 0 0 16 8c0-4.42-3.58-8-8-8z"></path></svg></a></div></div></nav><div class="wrap h1body-exist max-container"><header class="wrap-header h1wrap"><h1 id="tar-备忘清单"><!--?xml version="1.0" encoding="iso-8859-1"?-->
|
||
<!-- Generator: Adobe Illustrator 19.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||
<svg version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" fill="currentColor" height="1em" width="1em" viewBox="0 0 48 48" style="enable-background:new 0 0 48 48;" xml:space="preserve">
|
||
<g>
|
||
<g>
|
||
<path d="M47.987,21.938c-0.006-0.091-0.023-0.178-0.053-0.264c-0.011-0.032-0.019-0.063-0.033-0.094
|
||
c-0.048-0.104-0.109-0.202-0.193-0.285c-0.001-0.001-0.001-0.001-0.001-0.001L42,15.586V10c0-0.022-0.011-0.041-0.013-0.063
|
||
c-0.006-0.088-0.023-0.173-0.051-0.257c-0.011-0.032-0.019-0.063-0.034-0.094c-0.049-0.106-0.11-0.207-0.196-0.293l-9-9
|
||
c-0.086-0.086-0.187-0.148-0.294-0.196c-0.03-0.014-0.06-0.022-0.091-0.032c-0.085-0.03-0.172-0.047-0.263-0.052
|
||
C32.039,0.01,32.021,0,32,0H7C6.448,0,6,0.448,6,1v14.586l-5.707,5.707c0,0-0.001,0.001-0.002,0.002
|
||
c-0.084,0.084-0.144,0.182-0.192,0.285c-0.014,0.031-0.022,0.062-0.033,0.094c-0.03,0.086-0.048,0.173-0.053,0.264
|
||
C0.011,21.96,0,21.978,0,22v19c0,0.552,0.448,1,1,1h5v5c0,0.552,0.448,1,1,1h34c0.552,0,1-0.448,1-1v-5h5c0.552,0,1-0.448,1-1V22
|
||
C48,21.978,47.989,21.96,47.987,21.938z M44.586,21H42v-2.586L44.586,21z M38.586,9H33V3.414L38.586,9z M8,2h23v8
|
||
c0,0.552,0.448,1,1,1h8v5v5H8v-5V2z M6,18.414V21H3.414L6,18.414z M40,46H8v-4h32V46z M46,40H2V23h5h34h5V40z"></path>
|
||
<path d="M33.86,32.143c0.221-0.153,0.422-0.354,0.604-0.603c0.181-0.249,0.332-0.552,0.451-0.91
|
||
c0.119-0.357,0.179-0.767,0.179-1.232c0-0.601-0.085-1.116-0.255-1.547c-0.17-0.431-0.405-0.788-0.706-1.071
|
||
c-0.3-0.283-0.66-0.49-1.079-0.621c-0.419-0.13-0.878-0.195-1.377-0.195h-3.434V38h1.972v-5.134h1.139L33.222,38h2.142
|
||
l-2.159-5.542C33.421,32.401,33.639,32.297,33.86,32.143z M32.602,30.902c-0.323,0.312-0.734,0.468-1.233,0.468h-1.156v-3.706
|
||
h1.156c0.204,0,0.408,0.028,0.612,0.085s0.388,0.153,0.552,0.289s0.298,0.323,0.4,0.561s0.153,0.538,0.153,0.901
|
||
C33.086,30.123,32.925,30.591,32.602,30.902z"></path>
|
||
<path d="M21.441,25.964L18.449,38h2.04l0.612-2.55h3.162L24.858,38h2.125l-2.941-12.036H21.441z M21.357,33.852l1.309-5.967h0.068
|
||
l1.275,5.967H21.357z"></path>
|
||
<polygon points="18.756,25.964 12.227,25.964 12.227,27.698 14.488,27.698 14.488,38 16.494,38 16.494,27.698 18.756,27.698 "></polygon>
|
||
</g>
|
||
</g>
|
||
</svg>
|
||
<a aria-hidden="true" tabindex="-1" href="#tar-备忘清单"><span class="icon icon-link"></span></a>tar 备忘清单</h1><div class="wrap-body">
|
||
<p>这是 tar 常用命令的快速参考备忘单。</p>
|
||
</div></header><div class="menu-tocs"><div class="menu-btn"><svg aria-hidden="true" fill="currentColor" height="1em" width="1em" viewBox="0 0 16 16" version="1.1" data-view-component="true">
|
||
<path fill-rule="evenodd" d="M2 4a1 1 0 100-2 1 1 0 000 2zm3.75-1.5a.75.75 0 000 1.5h8.5a.75.75 0 000-1.5h-8.5zm0 5a.75.75 0 000 1.5h8.5a.75.75 0 000-1.5h-8.5zm0 5a.75.75 0 000 1.5h8.5a.75.75 0 000-1.5h-8.5zM3 8a1 1 0 11-2 0 1 1 0 012 0zm-1 6a1 1 0 100-2 1 1 0 000 2z"></path>
|
||
</svg></div><div class="menu-modal"><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#入门">入门</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#介绍">介绍</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#语法">语法</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#选项">选项</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#创建一个-tar-格式的压缩文件">创建一个 tar 格式的压缩文件</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#创建压缩后的-targz-存档文件">创建压缩后的 tar.gz 存档文件</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#生成压缩率更高的-tarbz2-文件">生成压缩率更高的 tar.bz2 文件</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#解压缩-tar-文件">解压缩 tar 文件</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#解压缩-targz-文件">解压缩 tar.gz 文件</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#解压缩-tarbz2-文件">解压缩 tar.bz2 文件</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#列出归档内容">列出归档内容</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#从-tar-归档文件中提取单个文件">从 tar 归档文件中提取单个文件</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#从-tar-归档文件中提取多个文件">从 tar 归档文件中提取多个文件</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#使用通配符提取文件组">使用通配符提取文件组</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#添加文件或目录到-tar-存档中">添加文件或目录到 tar 存档中</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#另见">另见</a></div></div><div class="h1wrap-body"><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="入门"><a aria-hidden="true" tabindex="-1" href="#入门"><span class="icon icon-link"></span></a>入门</h2><div class="wrap-body">
|
||
</div></div><div class="h2wrap-body"><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="介绍"><a aria-hidden="true" tabindex="-1" href="#介绍"><span class="icon icon-link"></span></a>介绍</h3><div class="wrap-body">
|
||
<p>在Linux平台上,<code>tar</code> 命令是主要的归档实用程序。了解各种 <code>tar</code> 命令选项将帮助您掌握归档文件操作。<code>tar</code> 代表磁带存档。</p>
|
||
<h4 id="语法"><a aria-hidden="true" tabindex="-1" href="#语法"><span class="icon icon-link"></span></a>语法</h4>
|
||
<pre class="wrap-text "><code class="language-shell code-highlight"><span class="code-line"><span class="token function">tar</span> <span class="token punctuation">[</span>-ABcdgGhiklmMoOpPrRsStuUvwWxzZ<span class="token punctuation">]</span><span class="token punctuation">[</span>-C <span class="token operator"><</span>目的目录<span class="token operator">></span><span class="token punctuation">]</span><span class="token punctuation">[</span>-f <span class="token operator"><</span>备份文件<span class="token operator">></span><span class="token punctuation">]</span><span class="token punctuation">[</span>--delete<span class="token punctuation">]</span><span class="token punctuation">[</span>--totals<span class="token punctuation">]</span><span class="token punctuation">[</span>文件或目录<span class="token punctuation">..</span>.<span class="token punctuation">]</span>
|
||
</span></code></pre>
|
||
<!--rehype:className=wrap-text -->
|
||
<p>以前 unix 系统管理员使用 <code>tar</code> 执行磁带机备份。<code>tar</code> 命令用于获取文件和目录的集合,并生成高度压缩的归档文件,在Linux中通常称为 <code>tarball</code> 或 <code>tar</code>、<code>gzip</code> 和 <code>bzip</code>。</p>
|
||
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="选项"><a aria-hidden="true" tabindex="-1" href="#选项"><span class="icon icon-link"></span></a>选项</h3><div class="wrap-body">
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<table><thead><tr><th align="left">:-</th><th>-</th></tr></thead><tbody><tr><td align="left"><code>-c</code></td><td>建立新的备份文件</td></tr><tr><td align="left"><code>-C</code></td><td>切换到指定的目录</td></tr><tr><td align="left"><code>-d</code></td><td>对比备份文件内和文件系统上的文件的差异</td></tr><tr><td align="left"><code>-x</code></td><td>解压缩归档文件</td></tr><tr><td align="left"><code>-v</code></td><td>显示指令执行过程</td></tr><tr><td align="left"><code>-f</code></td><td>指定归档文件的文件名</td></tr><tr><td align="left"><code>-t</code></td><td>查看归档文件内容</td></tr><tr><td align="left"><code>-j</code></td><td>通过 bzip2 指令处理备份文件</td></tr><tr><td align="left"><code>-z</code></td><td>通过 gzip 指令处理备份文件</td></tr><tr><td align="left"><code>-r</code></td><td>向现有存档文件追加或更新文件或目录</td></tr><tr><td align="left"><code>-W</code></td><td>验证归档文件</td></tr><tr><td align="left"><code>--totals</code></td><td>备份文件建立后,列出文件大小</td></tr><tr><td align="left"><code>--delete</code></td><td>从备份文件中删除指定的文件</td></tr><tr><td align="left"><code>--wildcards</code></td><td>在 unix tar 命令中指定匹配模式</td></tr></tbody></table>
|
||
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="创建一个-tar-格式的压缩文件"><a aria-hidden="true" tabindex="-1" href="#创建一个-tar-格式的压缩文件"><span class="icon icon-link"></span></a>创建一个 tar 格式的压缩文件</h3><div class="wrap-body">
|
||
<p>在当前工作目录的 <code>/home/cyberpunk/testdir</code> 目录下创建一个名为 <code>archive.tar</code> 的 <code>tar</code> 归档文件:</p>
|
||
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line"><span class="token function">tar</span> <span class="token parameter variable">-cvf</span> archive.tar /home/cyberpunk/testdir/
|
||
</span><span class="code-line">
|
||
</span><span class="code-line">/home/cyberpunk/testdir/
|
||
</span><span class="code-line">/home/cyberpunk/testdir/file1.txt
|
||
</span><span class="code-line">/home/cyberpunk/testdir/file2.sh
|
||
</span><span class="code-line">/home/cyberpunk/testdir/file3.tar
|
||
</span></code></pre>
|
||
<p>本例中使用的选项有:</p>
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<table><thead><tr><th align="left">:-</th><th>-</th></tr></thead><tbody><tr><td align="left"><code>-c</code></td><td>建立新的备份文件</td></tr><tr><td align="left"><code>-v</code></td><td>显示指令执行过程</td></tr><tr><td align="left"><code>-f</code></td><td>指定归档文件的文件名</td></tr></tbody></table>
|
||
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="创建压缩后的-targz-存档文件"><a aria-hidden="true" tabindex="-1" href="#创建压缩后的-targz-存档文件"><span class="icon icon-link"></span></a>创建压缩后的 <code>tar.gz</code> 存档文件</h3><div class="wrap-body">
|
||
<p>要创建一个压缩的 <code>gzip</code> 归档文件,我们需要使用选项 <code>z</code> 。</p>
|
||
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line"><span class="token function">tar</span> cvzf compressedArchive.tar.gz /home/cyberpunk/testdir
|
||
</span><span class="code-line">
|
||
</span><span class="code-line">/home/cyberpunk/testdir/
|
||
</span><span class="code-line">/home/cyberpunk/testdir/file1.txt
|
||
</span><span class="code-line">/home/cyberpunk/testdir/file2.jpg
|
||
</span><span class="code-line">/home/cyberpunk/testdir/file3.png
|
||
</span></code></pre>
|
||
<p>本例中使用的选项有:</p>
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<table><thead><tr><th align="left">:-</th><th>-</th></tr></thead><tbody><tr><td align="left"><code>-c</code></td><td>建立新的备份文件</td></tr><tr><td align="left"><code>-v</code></td><td>显示指令执行过程</td></tr><tr><td align="left"><code>-f</code></td><td>指定归档文件的文件名</td></tr><tr><td align="left"><code>-z</code></td><td>通过 <code>gzip</code> 指令处理备份文件</td></tr></tbody></table>
|
||
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="生成压缩率更高的-tarbz2-文件"><a aria-hidden="true" tabindex="-1" href="#生成压缩率更高的-tarbz2-文件"><span class="icon icon-link"></span></a>生成压缩率更高的 <code>tar.bz2</code> 文件</h3><div class="wrap-body">
|
||
<p><code>tar</code> 的 <code>bz2</code> 压缩,可以创建比 <code>gzip</code> 文件小的归档。<code>Bz2</code> 模式执行归档压缩和解压所需的时间比 <code>gzip</code> 模式多。通常,这个时间差可以忽略不计,但如果文件非常打,或者是文件数量非常多,那么时间差就会非常大。</p>
|
||
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line"><span class="token function">tar</span> cvfj Archive.tar.bz2 /home/cyberpunk/testdir
|
||
</span><span class="code-line">
|
||
</span><span class="code-line">/home/cyberpunk/testdir/
|
||
</span><span class="code-line">/home/cyberpunk/testdir/file1.txt
|
||
</span><span class="code-line">/home/cyberpunk/testdir/file2.txt
|
||
</span><span class="code-line">/home/cyberpunk/testdir/file3.txt
|
||
</span></code></pre>
|
||
<p>本例中使用的选项有:</p>
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<table><thead><tr><th align="left">:-</th><th>-</th></tr></thead><tbody><tr><td align="left"><code>-c</code></td><td>建立新的备份文件</td></tr><tr><td align="left"><code>-v</code></td><td>显示指令执行过程</td></tr><tr><td align="left"><code>-f</code></td><td>指定归档文件的文件名</td></tr><tr><td align="left"><code>-j</code></td><td>通过 bzip2 指令处理备份文件</td></tr></tbody></table>
|
||
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="解压缩-tar-文件"><a aria-hidden="true" tabindex="-1" href="#解压缩-tar-文件"><span class="icon icon-link"></span></a>解压缩 tar 文件</h3><div class="wrap-body">
|
||
<p>要解压缩(提取)一个tar文件,将 <code>x</code> (提取)选项传递给该命令
|
||
使用不带 <code>-C</code> 选项的命令将在当前工作目录中提取存档。<code>-C</code> 选项告诉命令在哪里提取存档文件。</p>
|
||
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line"><span class="token function">tar</span> <span class="token parameter variable">-xvf</span> Archive.tar <span class="token parameter variable">-C</span> /home/cyberpunk/testdir/
|
||
</span><span class="code-line">
|
||
</span><span class="code-line">/home/cyberpunk/testdir/
|
||
</span><span class="code-line">/home/cyberpunk/testdir/file1.txt
|
||
</span><span class="code-line">/home/cyberpunk/testdir/file2.txt
|
||
</span><span class="code-line">/home/cyberpunk/testdir/file3.txt
|
||
</span></code></pre>
|
||
<p>本例中使用的选项有:</p>
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<table><thead><tr><th align="left">:-</th><th>-</th></tr></thead><tbody><tr><td align="left"><code>-x</code></td><td>解压缩归档文件</td></tr><tr><td align="left"><code>-v</code></td><td>显示指令执行过程</td></tr><tr><td align="left"><code>-f</code></td><td>指定归档文件的文件名</td></tr></tbody></table>
|
||
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="解压缩-targz-文件"><a aria-hidden="true" tabindex="-1" href="#解压缩-targz-文件"><span class="icon icon-link"></span></a>解压缩 tar.gz 文件</h3><div class="wrap-body">
|
||
<p>小知识:使用 <code>tar</code> 命令创建的所有归档文件,都可以以相同的方式提取。</p>
|
||
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line"><span class="token function">tar</span> <span class="token parameter variable">-xvf</span> Archive.tar.gz
|
||
</span><span class="code-line">
|
||
</span><span class="code-line">/home/cyberpunk/testdir/
|
||
</span><span class="code-line">/home/cyberpunk/testdir/file1.txt
|
||
</span><span class="code-line">/home/cyberpunk/testdir/file2.txt
|
||
</span><span class="code-line">/home/cyberpunk/testdir/file3.txt
|
||
</span></code></pre>
|
||
<p>本例中使用的选项有:</p>
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<table><thead><tr><th align="left">:-</th><th>-</th></tr></thead><tbody><tr><td align="left"><code>-x</code></td><td>解压缩归档文件</td></tr><tr><td align="left"><code>-v</code></td><td>显示指令执行过程</td></tr><tr><td align="left"><code>-f</code></td><td>指定归档文件的文件名</td></tr></tbody></table>
|
||
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="解压缩-tarbz2-文件"><a aria-hidden="true" tabindex="-1" href="#解压缩-tarbz2-文件"><span class="icon icon-link"></span></a>解压缩 tar.bz2 文件</h3><div class="wrap-body">
|
||
<p>小知识:使用 <code>tar</code> 命令创建的所有归档文件,都可以以相同的方式提取。</p>
|
||
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line"><span class="token function">tar</span> <span class="token parameter variable">-xvf</span> Archive.tar.bz2
|
||
</span><span class="code-line">
|
||
</span><span class="code-line">/home/cyberpunk/testdir/
|
||
</span><span class="code-line">/home/cyberpunk/testdir/file1.txt
|
||
</span><span class="code-line">/home/cyberpunk/testdir/file2.txt
|
||
</span><span class="code-line">/home/cyberpunk/testdir/file3.txt
|
||
</span></code></pre>
|
||
<p>本例中使用的选项有:</p>
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<table><thead><tr><th align="left">:-</th><th>-</th></tr></thead><tbody><tr><td align="left"><code>-x</code></td><td>解压缩归档文件</td></tr><tr><td align="left"><code>-v</code></td><td>显示指令执行过程</td></tr><tr><td align="left"><code>-f</code></td><td>指定归档文件的文件名</td></tr></tbody></table>
|
||
</div></div></div><div class="wrap h3body-not-exist col-span-1 row-span-2"><div class="wrap-header h3wrap"><h3 id="列出归档内容"><a aria-hidden="true" tabindex="-1" href="#列出归档内容"><span class="icon icon-link"></span></a>列出归档内容</h3><div class="wrap-body">
|
||
<!--rehype:wrap-class=col-span-1 row-span-2-->
|
||
<p>使用 <code>t</code> 选项列出 <code>tar</code> 归档文件的内容:</p>
|
||
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line"><span class="token comment"># tar -tvf uploadprogress.tar</span>
|
||
</span><span class="code-line">
|
||
</span><span class="code-line">-rwxr--r-- root/root <span class="token number">1111</span> <span class="token number">2014</span>-10-19 <span class="token number">12</span>:33:42 file1.txt
|
||
</span><span class="code-line">-rwxr--r-- root/root <span class="token number">1111</span> <span class="token number">2014</span>-10-19 <span class="token number">12</span>:33:42 file2.txt
|
||
</span><span class="code-line">-rwxr--r-- root/root <span class="token number">1111</span> <span class="token number">2014</span>-10-19 <span class="token number">12</span>:33:42 file3.txt
|
||
</span><span class="code-line">-rwxr--r-- root/root <span class="token number">1111</span> <span class="token number">2014</span>-10-19 <span class="token number">12</span>:33:42 file4.txt
|
||
</span></code></pre>
|
||
<p>本例中使用的选项有:</p>
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<table><thead><tr><th align="left">:-</th><th>-</th></tr></thead><tbody><tr><td align="left"><code>-t</code></td><td>查看归档文件内容</td></tr><tr><td align="left"><code>-v</code></td><td>显示指令执行过程</td></tr><tr><td align="left"><code>-f</code></td><td>指定归档文件的文件名</td></tr></tbody></table>
|
||
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="从-tar-归档文件中提取单个文件"><a aria-hidden="true" tabindex="-1" href="#从-tar-归档文件中提取单个文件"><span class="icon icon-link"></span></a>从 tar 归档文件中提取单个文件</h3><div class="wrap-body">
|
||
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line"><span class="token function">tar</span> <span class="token parameter variable">--extract</span> <span class="token parameter variable">--file</span><span class="token operator">=</span>archive.tar file1.txt
|
||
</span><span class="code-line">
|
||
</span><span class="code-line">file1.txt
|
||
</span></code></pre>
|
||
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="从-tar-归档文件中提取多个文件"><a aria-hidden="true" tabindex="-1" href="#从-tar-归档文件中提取多个文件"><span class="icon icon-link"></span></a>从 tar 归档文件中提取多个文件</h3><div class="wrap-body">
|
||
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line"><span class="token function">tar</span> <span class="token parameter variable">-xvf</span> Archive.tar <span class="token string">"file 1"</span> <span class="token string">"file 2"</span>
|
||
</span></code></pre>
|
||
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="使用通配符提取文件组"><a aria-hidden="true" tabindex="-1" href="#使用通配符提取文件组"><span class="icon icon-link"></span></a>使用通配符提取文件组</h3><div class="wrap-body">
|
||
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line"><span class="token comment"># tar -xvf Archive.tar --wildcards *.txt'</span>
|
||
</span><span class="code-line">
|
||
</span><span class="code-line">/home/cyberpunk/testdir/file1.txt
|
||
</span><span class="code-line">/home/cyberpunk/testdir/file2.txt
|
||
</span><span class="code-line">/home/cyberpunk/testdir/file3.txt
|
||
</span></code></pre>
|
||
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="添加文件或目录到-tar-存档中"><a aria-hidden="true" tabindex="-1" href="#添加文件或目录到-tar-存档中"><span class="icon icon-link"></span></a>添加文件或目录到 tar 存档中</h3><div class="wrap-body">
|
||
<p>要向现有的 <code>tar</code> 文件中添加文件或目录,可以使用 <code>r</code> 选项。例如,我们将 <code>xyz.txt</code> 文件和 <code>php</code> 目录添加到现有的 <code>tecmint-14-09-12.tar</code> 归档文件中。</p>
|
||
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line"><span class="token comment"># tar -rvf Archive.tar xyz.txt #add file</span>
|
||
</span><span class="code-line">or
|
||
</span><span class="code-line"><span class="token comment"># tar -rvf Archive.tar php # add directory</span>
|
||
</span></code></pre>
|
||
</div></div></div></div></div><div class="wrap h2body-not-exist"><div class="wrap-header h2wrap"><h2 id="另见"><a aria-hidden="true" tabindex="-1" href="#另见"><span class="icon icon-link"></span></a>另见</h2><div class="wrap-body">
|
||
<p><a href="https://neverendingsecurity.wordpress.com/2015/04/13/linux-tar-commands-cheatsheet/">Linux Tar Commands Cheatsheet</a></p>
|
||
</div></div><div class="h2wrap-body"></div></div></div></div><footer class="footer-wrap"><footer class="max-container">© 2022 Kenny Wang.</footer></footer><script src="../data.js?v=1.3.6" defer></script><script src="../js/fuse.min.js?v=1.3.6" defer></script><script src="../js/main.js?v=1.3.6" defer></script><div id="mysearch"><div class="mysearch-box"><div class="mysearch-input"><div><svg xmlns="http://www.w3.org/2000/svg" height="1em" width="1em" viewBox="0 0 18 18">
|
||
<path fill="currentColor" d="M17.71,16.29 L14.31,12.9 C15.4069846,11.5024547 16.0022094,9.77665502 16,8 C16,3.581722 12.418278,0 8,0 C3.581722,0 0,3.581722 0,8 C0,12.418278 3.581722,16 8,16 C9.77665502,16.0022094 11.5024547,15.4069846 12.9,14.31 L16.29,17.71 C16.4777666,17.8993127 16.7333625,18.0057983 17,18.0057983 C17.2666375,18.0057983 17.5222334,17.8993127 17.71,17.71 C17.8993127,17.5222334 18.0057983,17.2666375 18.0057983,17 C18.0057983,16.7333625 17.8993127,16.4777666 17.71,16.29 Z M2,8 C2,4.6862915 4.6862915,2 8,2 C11.3137085,2 14,4.6862915 14,8 C14,11.3137085 11.3137085,14 8,14 C4.6862915,14 2,11.3137085 2,8 Z"></path>
|
||
</svg><input id="mysearch-input" type="search" placeholder="搜索" autocomplete="off"><div class="mysearch-clear"></div></div><button id="mysearch-close" type="button">搜索</button></div><div class="mysearch-result"><div id="mysearch-menu"></div><div id="mysearch-content"></div></div></div></div></body>
|
||
</html>
|