什么是TLDR?
TLDR 它本身
tl;dr 是一個網絡詞匯,和十動然拒這類差不多,是個縮寫。它的全稱是「Too Long; Don't Read」,翻譯成中文的話就叫「太長不看」。它興起于一些論壇,為了說明「樓主你的破文章又臭又長」,不過后來有許多文章的開頭也用
這個東西為啥叫太長不看?
一個叫「太長不看」的命令行工具顯然是解決一些令程序員一個腦袋兩個大的太長的東西,而這個東西就是 Linux man pages。它到底有多長呢,man pages的官方壓縮包是 2M 多的大小,解壓后是 16M。 16M 確實不算大了,然而這 16M 可是純文本啊。用來做類比的話,一本50萬字的中文小說變成純文本文件之后也就那么 1M 多,可想而知這甚至是全英文 man pages 有多長了。
我們卻需要它
作為程序員有時又十分需要 man pages。 雖然它長,你又不得不去讀它:比如說,你知道 ssh 的基本用法是
ssh username@remote_host
然而當你想換個端口或是利用私鑰登入服務器的時候就傻眼了,不得不打開 man pages:
SH(1) BSD General Commands Manual SSH(1)
NAME
ssh -- OpenSSH SSH client (remote login program)
SYNOPSIS
ssh [-1246AaCfGgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec]
[-D [bind_address:]port] [-E log_file] [-e escape_char]
[-F configfile] [-I pkcs11] [-i identity_file]
[-J [user@]host[:port]] [-L address] [-l login_name] [-m mac_spec]
[-O ctl_cmd] [-o option] [-p port] [-Q query_option] [-R address]
[-S ctl_path] [-W host:port] [-w local_tun[:remote_tun]]
[user@]hostname [command]
DESCRIPTION
以下省略一萬字……
于是想找如何使用私鑰登錄的你感到了一陣絕望……(雖然它確實存在于[-i identity_file]這里,你找到了嗎?)
所以就有了 TLDR
tldr 很好地解決了這個問題,把 man pages 中最常用的選項用更簡單的方式敘述了出來:
$ tldr ssh
ssh
Secure Shell is a protocol used to securely log onto remote systems.
It can be used for logging or executing commands on a remote server.
- Connect to a remote server:
ssh username@remote_host
- Connect to a remote server with a specific identity (private key):
ssh -i path/to/key_file username@remote_host
- Connect to a remote server using a specific port:
ssh username@remote_host -p 2222
- Run a command on a remote server:
ssh remote_host command -with -flags
- SSH tunneling: Dynamic port forwarding (SOCKS proxy on localhost:9999):
ssh -D 9999 -C username@remote_host
- SSH tunneling: Forward a specific port (localhost:9999 to slashdot.org:80):
ssh -L 9999:slashdot.org:80 username@remote_host
- Enable the option to forward the authentication information to the remote machine (see man ssh_config for available options):
ssh -o "ForwardAgent=yes" username@remote_host
是的,tldr 的 ssh page 就這么長,而且你幾乎還能一下就找到怎么使用私鑰登錄。雖然它確實非常不全,但是它可以解決你絕大部分想查 man 的問題。
而且它是社區驅動的呀!
它是一個開源的項目,每個人都可以為它貢獻或修改其中的 page。如果你想去圍觀這個作品,可以到 tldr 這個 GitHub 代碼倉庫去做出一些自己的貢獻。
安裝和使用
網頁版
最簡單的使用方法是打開網頁版。在上方的搜索框中找到你想查看的命令。例如:
Node.js 版本
TLDR 最初的版本用 Node.js 寫成,所以官方最為推薦的安裝方法是:
npm install -g tldr
如果你不了解以下一接中提到的任何一種編程語言/包管理器(當然我覺得這種情況也不需要這個破軟件就是了),我們也在這里推薦使用 npm 安裝。如果你還沒有 npm, 可以到這里下載。
其他版本
TLDR 的官網也給除了其他一些安裝方式:
Client | Installation instructions |
---|---|
Ruby client | gem install tldrb |
Haskell client | stack install tldr |
Python client | pip install tldr.py |
C++ client | brew install tldr |
Android client | tldr-viewer on Google Play |
iOS client | TLDR Man Page in App Store |
Dash for OSX | open Preferences > Downloads > User Contributed and find tldr pages in the list |
Bash client | bpkg install pepa65/tldr |
使用方法
簡單而言,你只要在命令行輸入 tldr
加上任何命令即可,例如 tldr ssh
或是 tldr tar
,你就可以獲得在第一節中所見的簡潔的介紹啦!