对于 Linux 用户来说,​​man​​​ 应该是最常用的命令之一了,它主要用于显示某个命令/实用程序的详细说明,通常被称为​​“手册页”​​。

虽然 man 很强大,但却时常会让人崩溃,​​满屏的选项和解释,简直是又臭又长。​​​为了解决这一问题,​​tldr 应运而生了。​

Linux 命令总记不住?一招帮你搞定!_nagios

Life is short, You need tldr

tldr 是​​『Too Long; Didn't Read』​​​的缩写,形容​​太长而不值得一读​​​的意思(这不就是指的 man 吗)。它简化了烦琐的 man 帮助文档,​​仅列出了 Linux 命令中最常用的一些用法,简洁清晰、自然易懂。​

  • GitHub 地址:https://github.com/tldr-pages/tldr

1

安装 tldr

tldr 有多种语言(例如:Python、Go、Node.js 等)编写的客户端,​​但据官网所述,目前最成熟的客户端是基于 Node.js 的,​​可以使用 npm 包管理器轻松地安装它。

如果之前没有安装过 nodejs 和 npm,需要先进行安装:

$ sudo apt install nodejs
$ sudo apt install npm

​为了方便后续快速下载,更新一下 npm 的包镜像源:​

$ sudo npm config set registry https://registry.npm.taobao.org

全局安装 n 管理器,并升级 nodejs 为最新稳定版:

$ sudo npm install -g n
$ sudo n stable

随后,就可以安装 tldr 客户端了:

$ sudo npm install -g tldr

一旦安装完成,最好在使用之前更新下缓存:

$ tldr --update

2

基本用法

tldr 的使用非常简单,​​后面直接跟想要查询的命令就可以啦!​

来看一个例子,显示 tar 命令的相关文档:

$ tldr tar
tar
Archiving utility.Often combined with a compression method, such as gzip or bzip.More information: https://www.gnu.org/software/tar.

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

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

- Create a gzipped archive from a directory using relative paths:
tar czf {{target.tar.gz}} -C {{path/to/directory}} .

- Extract a (compressed) archive into the current directory:
tar xf {{source.tar[.gz|.bz2|.xz]}}

- Extract a (compressed) archive into the target directory:
tar xf {{source.tar[.gz|.bz2|.xz]}} -C {{directory}}

- 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}}"

- Extract a specific file without preserving the folder structure:
tar xf {{source.tar}} {{source.tar/path/to/extract}} --strip-components={{depth_to_strip}}

怎么样,可以很容易地找到命令的具体用法吧!

如果要显示帮助页面,执行命令:

$ tldr --help

哈哈,绝对的神器,Cheers!

·END·

Linux 命令总记不住?一招帮你搞定!_npm_02