Unix 的命令實在太多,忘記某个工具的名字是常事,不常用的尤其如此。與其翻半天文件,不如記住 apropos 這個救命繩。
想找一台計算機,直接問 apropos(等效的 man -k 也行):
$ apropos calculator bc (1) - An arbitrary precision calculator language dc (1) - An arbitrary precision calculator
每個工具的手冊頁都有一段簡短描述,apropos 就是在這些描述裡搜尋關鍵字。關鍵字可以是字面值,也可以是正則表達式,例如:
$ apropos "calcu*" allcm (1) - force the most important Computer-Modern-fonts to be calculated allec (1) - force the most important Computer-Modern-fonts to be calculated allneeded (1) - force the calculation of all fonts now needed bc (1) - An arbitrary precision calculator language dc (1) - An arbitrary precision calculator
使用正則表達式時,記得把整串放在引號裡,免得 shell 先替你解釋那些特殊字元。
如上所見,dc 幾乎每台 Unix 都有。不帶參數執行會進入互動模式,用 Reverse Polish Notation(逆波蘭表示法)運算:
$ dc 5 6 * 10 / p 3
但其實你可以把整串寫在命令列上,用 -e 帶入運算式,同樣要加引號:
$ dc -e "5 6 * 10 /" 3
兩個小工具,一個替你找回忘掉的命令,一個讓你不必開計算機應用程式。效率往往就是這樣一點一滴累積出來的。