<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Terminal on 凡·间</title>
    <link>https://16bh.github.io/tags/terminal/</link>
    <description>Recent content in Terminal on 凡·间</description>
    <generator>Hugo</generator>
    <language>zh-cn</language>
    <lastBuildDate>Tue, 16 Oct 2018 23:05:10 +0800</lastBuildDate>
    <atom:link href="https://16bh.github.io/tags/terminal/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>一款比man更好用的工具：tldr</title>
      <link>https://16bh.github.io/2018/10/16/a-command-more-powerful-than-man/</link>
      <pubDate>Tue, 16 Oct 2018 23:05:10 +0800</pubDate>
      <guid>https://16bh.github.io/2018/10/16/a-command-more-powerful-than-man/</guid>
      <description>&lt;p&gt;感谢duang duang给我介绍的一款实用的小工具:tldr&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;http://tldr-pages.github.io/&#34;&gt;tldr的官网介绍&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;tldr = too long don&amp;rsquo;t read&lt;/p&gt;
&lt;p&gt;通常我们碰到一个陌生或很长时间没用过的command命令的时候不会用，会用man来查看这个命令的用法，但是man的介绍太详细了，如下所示：&lt;/p&gt;</description>
      <content:encoded><![CDATA[<p>感谢duang duang给我介绍的一款实用的小工具:tldr</p>
<p><a href="http://tldr-pages.github.io/">tldr的官网介绍</a></p>
<p>tldr = too long don&rsquo;t read</p>
<p>通常我们碰到一个陌生或很长时间没用过的command命令的时候不会用，会用man来查看这个命令的用法，但是man的介绍太详细了，如下所示：</p>
<p>以下是截取的一部分命令介绍：</p>
<pre tabindex="0"><code>BSDTAR(1)                 BSD General Commands Manual                BSDTAR(1)

NAME
     tar -- manipulate tape archives

SYNOPSIS
     tar [bundled-flags &lt;args&gt;] [&lt;file&gt; | 
&lt;pattern&gt;
 ...]
     tar {-c} [options] [files | directories]
     tar {-r | -u} -f archive-file [options] [files | directories]
     tar {-t | -x} [options] [patterns]

DESCRIPTION
     tar creates and manipulates streaming archive files.  This implementation
     can extract from tar, pax, cpio, zip, jar, ar, and ISO 9660 cdrom images
     and can create tar, pax, cpio, ar, and shar archives.

     The first synopsis form shows a ``bundled&#39;&#39; option word.  This usage is
     provided for compatibility with historical implementations.  See COMPATI-
     BILITY below for details.

     The other synopsis forms show the preferred usage.  The first option to
     tar is a mode indicator from the following list:
     -c      Create a new archive containing the specified items.
     -r      Like -c, but new entries are appended to the archive.  Note that
             this only works on uncompressed archives stored in regular files.
             The -f option is required.
     -t      List archive contents to stdout.
     -u      Like -r, but new entries are added only if they have a modifica-
             tion date newer than the corresponding entry in the archive.
             Note that this only works on uncompressed archives stored in reg-
             ular files.  The -f option is required.
</code></pre><p>急等着一个命令用的时候，真的是欲仙欲死。</p>
<p>比较一下，用<code>tldr</code>查询<code>tar</code>的结果：</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-shell" data-lang="shell"><span class="line"><span class="cl">➜  ~ tldr tar
</span></span><span class="line"><span class="cl">Local data is older than two weeks, use --update to update it.
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">tar
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">Archiving utility.
</span></span><span class="line"><span class="cl">Often combined with a compression method, such as gzip or bzip.
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">- Create an archive from files:
</span></span><span class="line"><span class="cl">    tar cf target.tar file1 file2 file3
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">- Create a gzipped archive:
</span></span><span class="line"><span class="cl">    tar czf target.tar.gz file1 file2 file3
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">- Extract an archive in a target folder:
</span></span><span class="line"><span class="cl">    tar xf source.tar -C folder
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">- Extract a gzipped archive in the current directory:
</span></span><span class="line"><span class="cl">    tar xzf source.tar.gz
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">- Extract a bzipped archive in the current directory:
</span></span><span class="line"><span class="cl">    tar xjf source.tar.bz2
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">- Create a compressed archive, using archive suffix to determine the compression program:
</span></span><span class="line"><span class="cl">    tar caf target.tar.xz file1 file2 file3
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">- List the contents of a tar file:
</span></span><span class="line"><span class="cl">    tar tvf source.tar
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">- Extract files matching a pattern:
</span></span><span class="line"><span class="cl">    tar xf source.tar --wildcards <span class="s2">&#34;*.html&#34;</span>
</span></span></code></pre></div><p>根据示例，立马就知道这个命令的常见用法了。</p>
<p>最后，把tldr设置成man的alias别名，更方便日常的使用</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-shell" data-lang="shell"><span class="line"><span class="cl"><span class="nb">alias</span> <span class="nv">man</span><span class="o">=</span><span class="s2">&#34;tldr&#34;</span>
</span></span></code></pre></div><h2 id="补充tldr-今天更好用了">补充：tldr 今天更好用了</h2>
<h3 id="1-安装方式">1. 安装方式</h3>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-shell" data-lang="shell"><span class="line"><span class="cl">brew install tldr
</span></span></code></pre></div><p>注意 Homebrew 里的 <code>tldr</code> 是一个<strong>客户端</strong>，具体实现有多个（<code>tealdeer</code> 是 Rust 写的、更快；<code>tldr</code> 官方客户端是 Node/Go 实现）。<code>brew install tealdeer</code> 也是一个常见选择，命令名仍是 <code>tldr</code>。</p>
<h3 id="2-第一次用要先更新缓存">2. 第一次用要先更新缓存</h3>
<p>原文的输出里有一句很关键但容易被忽略：</p>
<pre tabindex="0"><code>Local data is older than two weeks, use --update to update it.
</code></pre><p>现代的 tldr 客户端<strong>默认不带任何页面数据</strong>，需要：</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-shell" data-lang="shell"><span class="line"><span class="cl">tldr --update
</span></span></code></pre></div><p>否则会提示「找不到页面」。这也是新手最常见的困惑。</p>
<h3 id="3-关于-alias-mantldr">3. 关于 <code>alias man=&quot;tldr&quot;</code></h3>
<p><strong>不建议这么做。</strong> 理由：</p>
<ul>
<li><code>man</code> 偶尔会出现在脚本里，改别名只在交互 shell 生效，容易造成「我这能跑你那不能跑」。</li>
<li>tldr 只给例子，<strong>不给完整的参数说明</strong>，遇到边缘参数时还是要 <code>man</code>。</li>
<li>更稳妥的是给 tldr 一个短别名：<code>alias t='tldr'</code>，两者并存。</li>
</ul>
<h3 id="4-中文页面">4. 中文页面</h3>
<p>tldr 支持中文：</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-shell" data-lang="shell"><span class="line"><span class="cl">tldr --language zh tar
</span></span></code></pre></div><p>设置默认语言后（<code>tldr --configure</code> 或在配置里写 <code>language: zh</code>），日常使用体验更好。</p>
<h3 id="5-一条经验">5. 一条经验</h3>
<p>tldr 适合**「我知道有这个命令，但忘了怎么用」<strong>；不适合</strong>「我要知道这个命令的某个冷门选项」**。前者用 tldr，后者用 <code>man</code> 或 <code>tldr --update</code> 之后的 <code>command --help</code>，别指望一个替代另一个。</p>
<p><em>本文整理于 2018 年，2026 年 11 月补充。</em></p>]]></content:encoded>
    </item>
    <item>
      <title>在终端跳快速跳转到指定目录的oh-my-zsh插件：z与wd</title>
      <link>https://16bh.github.io/2016/07/12/oh-my-zsh-plugin-wd/</link>
      <pubDate>Tue, 12 Jul 2016 12:05:02 +0800</pubDate>
      <guid>https://16bh.github.io/2016/07/12/oh-my-zsh-plugin-wd/</guid>
      <description>&lt;p&gt;&lt;code&gt;zsh&lt;/code&gt;的&lt;code&gt;z&lt;/code&gt;插件可以随意跳转最近经常打开的文件夹
&lt;code&gt;zsh&lt;/code&gt;的&lt;code&gt;wd&lt;/code&gt;插件可以任意跳转你标记过的文件夹&lt;/p&gt;</description>
      <content:encoded><![CDATA[<p><code>zsh</code>的<code>z</code>插件可以随意跳转最近经常打开的文件夹
<code>zsh</code>的<code>wd</code>插件可以任意跳转你标记过的文件夹</p>
<blockquote>
<p>前提，你必须要先安装iTerm2和oh my zsh</p>
</blockquote>
<p>试想一下这种场景：你想要修改nginx的配置，只知道大概在<code>/usr/local</code>目录下,不太清楚具体路径</p>
<p>你可能在终端这样输入：</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-shell" data-lang="shell"><span class="line"><span class="cl"><span class="nb">cd</span> /usr
</span></span><span class="line"><span class="cl">ll
</span></span><span class="line"><span class="cl"><span class="nb">cd</span> <span class="nb">local</span>
</span></span><span class="line"><span class="cl">ll
</span></span><span class="line"><span class="cl"><span class="nb">cd</span> etc
</span></span><span class="line"><span class="cl">ll
</span></span><span class="line"><span class="cl"><span class="nb">cd</span> nginx
</span></span><span class="line"><span class="cl">ll
</span></span><span class="line"><span class="cl">vim nginx.conf
</span></span></code></pre></div><p>看完这篇文章的介绍，你的生活将发生翻天覆地的变化。</p>
<p>如果你的电脑安装了<code>iterm2</code>和<code>oh－my－zsh</code>，再安装<code>z</code>或<code>wd</code>插件之后
你只需要执行：</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-shell" data-lang="shell"><span class="line"><span class="cl">z nginx
</span></span></code></pre></div><p>或</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-shell" data-lang="shell"><span class="line"><span class="cl">wd nginx
</span></span></code></pre></div><p>就能一秒直达<code>nginx</code>目录</p>
<h1 id="安装z和wd插件">安装<code>z</code>和<code>wd</code>插件</h1>
<p>安装zsh的插件</p>
<ol>
<li>打开用户目录下的<code>.zshrc</code>文件</li>
<li>修改<code>.zshrc</code>文件,在plugins后面的括号中加入<code>z</code> <code>wd</code>，两个插件的功能是类似的，选择一个安装就可以了</li>
</ol>
<pre tabindex="0"><code>plugins=(git z wd)
</code></pre><ol start="3">
<li>保存并重新加载<code>.zshrc</code>文件</li>
</ol>
<h1 id="使用z插件">使用<code>z</code>插件</h1>
<p>安装完<code>z</code>插件后</p>
<p>输入命令 <code>z</code> 即可查看你最近访问最频繁的目录
<img loading="lazy" src="/2016/07/12/oh-my-zsh-plugin-wd/1468333461556.png"></p>
<p>按<code>z</code>+目录名称的部分内容即可跳转目录
<img loading="lazy" src="/2016/07/12/oh-my-zsh-plugin-wd/1468334078114.png"></p>
<h1 id="使用wd插件">使用<code>wd</code>插件</h1>
<p>常用命令：</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-shell" data-lang="shell"><span class="line"><span class="cl">wd                  //查看所有可用命令
</span></span><span class="line"><span class="cl">wd add <span class="o">(</span>label_name<span class="o">)</span> //标记目录
</span></span><span class="line"><span class="cl">wd rm <span class="o">(</span>label_name<span class="o">)</span>  //去除目录标记
</span></span><span class="line"><span class="cl">wd list             //查看所有标记
</span></span></code></pre></div><p>使用方法很简单
进入一个你觉得很常用的目录,如上面提到的<code>usr/local/etc/nginx</code>,执行<code>wd add nginx</code>,相当于告诉终端：我喜欢这个目录，帮我记住它，什么还要取个名字，那就叫<code>nginx</code>吧。以后在任何位置，你只需要执行<code>wd nginx</code>，就能直接返回这个目录了</p>
<p>示例：
<img loading="lazy" src="/2016/07/12/oh-my-zsh-plugin-wd/1468333921006.png"></p>
<h2 id="补充z-和-wd-的取舍">补充：z 和 wd 的取舍</h2>
<h3 id="1-两个插件的定位差异">1. 两个插件的定位差异</h3>
<p>原文说「两个功能类似，选一个」，其实差别不小：</p>
<table>
	<thead>
			<tr>
					<th></th>
					<th><code>z</code></th>
					<th><code>wd</code></th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td>数据来源</td>
					<td><strong>自动</strong>记录你 cd 过的目录，按访问频率和时间打分</td>
					<td><strong>手动</strong> <code>wd add</code> 标记</td>
			</tr>
			<tr>
					<td>跳转依据</td>
					<td>模糊匹配路径里的任意片段</td>
					<td>精确匹配你起的别名</td>
			</tr>
			<tr>
					<td>适合场景</td>
					<td>目录多、路径长、经常去的地方</td>
					<td>目录少但名字不直观（<code>wd add pro</code> 代表项目目录）</td>
			</tr>
	</tbody>
</table>
<p>日常用<strong>只需要装 <code>z</code></strong>，<code>wd</code> 的价值在于给「名字和用途对不上」的目录起一个你自己记得住的名字。</p>
<h3 id="2-z-的数据存在哪什么时候会失效">2. <code>z</code> 的数据存在哪、什么时候会失效</h3>
<p><code>z</code> 的数据文件是 <code>~/.z</code>，它是一个<strong>按访问频率排序的纯文本列表</strong>。这带来两个后果：</p>
<ul>
<li>文件被删或换机器，历史就没了（可以手动同步这个文件）</li>
<li>目录<strong>被删除后不会自动移除</strong>，<code>z</code> 出来一堆已经不存在的老路径。清理：</li>
</ul>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-shell" data-lang="shell"><span class="line"><span class="cl"><span class="c1"># 只看不删</span>
</span></span><span class="line"><span class="cl">z -l <span class="p">|</span> head -20
</span></span><span class="line"><span class="cl"><span class="c1"># 重置全部历史</span>
</span></span><span class="line"><span class="cl">rm ~/.z
</span></span></code></pre></div><h3 id="3-拼写注意">3. 拼写注意</h3>
<p>原文写的是 <code>wd add (label_name)</code>，括号只是示意，<strong>实际命令里不要带括号</strong>：</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-shell" data-lang="shell"><span class="line"><span class="cl">wd add nginx     <span class="c1"># 对</span>
</span></span><span class="line"><span class="cl">wd add <span class="o">(</span>nginx<span class="o">)</span>   <span class="c1"># 错，会把括号也当成名字的一部分</span>
</span></span></code></pre></div><h3 id="4-如今的替代品">4. 如今的替代品</h3>
<ul>
<li><strong><code>fzf</code> + <code>Ctrl+T</code></strong>：模糊查找当前目录下的文件/目录，是这几年终端里最常用的一套。</li>
<li><strong><code>zoxide</code></strong>：<code>z</code> 的现代重写版，用 Rust 写的，安装一次即 <code>brew install zoxide</code>，体验几乎一致但更快，且支持多 shell。</li>
<li><strong><code>autojump</code></strong>：<code>z</code> 的另一个分支，思路相同。</li>
</ul>
<p>如果让我今天重装一遍，我会选 <code>zoxide</code>——它兼容 <code>z</code> 的用法，不需要额外配置。</p>
<p><em>本文整理于 2016 年，2026 年 11 月补充。</em></p>]]></content:encoded>
    </item>
  </channel>
</rss>
