感谢duang duang给我介绍的一款实用的小工具:tldr

tldr的官网介绍

tldr = too long don’t read

通常我们碰到一个陌生或很长时间没用过的command命令的时候不会用,会用man来查看这个命令的用法,但是man的介绍太详细了,如下所示:

以下是截取的一部分命令介绍:

BSDTAR(1)                 BSD General Commands Manual                BSDTAR(1)

NAME
     tar -- manipulate tape archives

SYNOPSIS
     tar [bundled-flags <args>] [<file> | 
<pattern>
 ...]
     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'' 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.

急等着一个命令用的时候,真的是欲仙欲死。

比较一下,用tldr查询tar的结果:

➜  ~ tldr tar
Local data is older than two weeks, use --update to update it.


tar

Archiving utility.
Often combined with a compression method, such as gzip or bzip.

- Create an archive from files:
    tar cf target.tar file1 file2 file3

- Create a gzipped archive:
    tar czf target.tar.gz file1 file2 file3

- Extract an archive in a target folder:
    tar xf source.tar -C folder

- Extract a gzipped archive in the current directory:
    tar xzf source.tar.gz

- Extract a bzipped archive in the current directory:
    tar xjf source.tar.bz2

- Create a compressed archive, using archive suffix to determine the compression program:
    tar caf target.tar.xz file1 file2 file3

- List the contents of a tar file:
    tar tvf source.tar

- Extract files matching a pattern:
    tar xf source.tar --wildcards "*.html"

根据示例,立马就知道这个命令的常见用法了。

最后,把tldr设置成man的alias别名,更方便日常的使用

alias man="tldr"

补充:tldr 今天更好用了

1. 安装方式

brew install tldr

注意 Homebrew 里的 tldr 是一个客户端,具体实现有多个(tealdeer 是 Rust 写的、更快;tldr 官方客户端是 Node/Go 实现)。brew install tealdeer 也是一个常见选择,命令名仍是 tldr。

2. 第一次用要先更新缓存

原文的输出里有一句很关键但容易被忽略:

Local data is older than two weeks, use --update to update it.

现代的 tldr 客户端默认不带任何页面数据,需要:

tldr --update

否则会提示「找不到页面」。这也是新手最常见的困惑。

3. 关于 alias man="tldr"

不建议这么做。 理由:

  • man 偶尔会出现在脚本里,改别名只在交互 shell 生效,容易造成「我这能跑你那不能跑」。
  • tldr 只给例子,不给完整的参数说明,遇到边缘参数时还是要 man。
  • 更稳妥的是给 tldr 一个短别名:alias t='tldr',两者并存。

4. 中文页面

tldr 支持中文:

tldr --language zh tar

设置默认语言后(tldr --configure 或在配置里写 language: zh),日常使用体验更好。

5. 一条经验

tldr 适合**「我知道有这个命令,但忘了怎么用」;不适合「我要知道这个命令的某个冷门选项」**。前者用 tldr,后者用 man 或 tldr --update 之后的 command --help,别指望一个替代另一个。

本文整理于 2018 年,2026 年 11 月补充。