萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 程式設計 >  >> 伺服器教學

Linux 內建說明系統完全攻略:man、info、help、whatis、apropos

Linux 哲學:「文檔即程式碼」。善用內建說明系統,比搜尋網路更快、更準、離線可用。本文系統整理 man、info、help、whatis、apropos 五大工具的用法與進階技巧。

一、man:傳統手冊頁

基本用法


man ls              # 顯示 ls 手冊
man 3 printf        # 顯示第 3 節(函式庫呼叫)的 printf
man -a exit         # 依序顯示所有節的 exit
man -k keyword      # 關鍵字搜尋(等同 apropos)
man -f ls           # 顯示簡短描述(等同 whatis)

手冊節號對照

節內容範例
1使用者指令ls, cp, grep
2系統呼叫open, read, fork
3函式庫呼叫printf, malloc, pthread_create
4特殊檔案/裝置/dev/null, /dev/tty
5檔案格式/慣例/etc/passwd, crontab
6遊戲fortune, snake
7概觀/慣例/協定man 7 regex, man 7 ip
8系統管理指令systemctl, fdisk, mkfs
9核心常式內核開發參考

瀏覽器操作

  • Space/f:下一頁
  • b:上一頁
  • /pattern:向下搜尋(n 下一筆,N 上一筆)
  • ?pattern:向上搜尋
  • q:離開
  • h:說明

進階技巧


# 列印為純文字(移除格式控制碼)
man ls | col -b > ls.txt

# 指定語言
man -L zh_TW ls
LC_ALL=zh_TW.UTF-8 man ls

# 搜尋所有手冊頁描述
man -k "file copy"
apropos "file copy"

二、info:GNU 超文本文檔系統

  • 結構化節點,支援超連結跳轉(像網頁)。
  • 通常比 man 更新、更詳細。
  • 操作:Space 下頁、Backspace 上頁、Enter 進入連結、l 返回、q 離開、h 教學。

info                # 進入主目錄
info coreutils      # 查看 coreutils 完整手冊
info ls             # 查看 ls 節點
info -k keyword     # 關鍵字搜尋

三、help:Shell 內建指令說明


help                # 列出所有內建指令
help cd             # 查看 cd 語法
help -m read        # 以 man 格式輸出
help -s printf      # 簡短用法摘要

常用內建指令:alias, bg, bind, break, builtin, caller, cd, command, compgen, complete, continue, declare, dirs, disown, echo, enable, eval, exec, exit, export, false, fc, fg, getopts, hash, help, history, jobs, kill, let, local, logout, mapfile, popd, printf, pushd, pwd, read, readonly, return, set, shift, shopt, source, suspend, test, times, trap, true, type, ulimit, umask, unalias, unset, wait。

四、whatis 與 apropos:快速查詢

指令資料來源搜尋方式輸出
whatis keywordmandb 資料庫精確匹配指令名單行描述
apropos keywordmandb 資料庫描述文本全文搜尋多行匹配結果

whatis ls
# ls (1) - list directory contents

apropos "list directory"
# ls (1) - list directory contents
# dir (1) - list directory contents
# vdir (1) - list directory contents

更新資料庫:mandb(通常由 cron.daily 自動執行)。

五、圖形化說明瀏覽器

  • KDE:khelpcenter / kdehelp
  • GNOME:gnome-help / yelp
  • 通用:xman(X11 版 man 瀏覽器)

六、離線文檔套件安裝


# Debian/Ubuntu
apt-get install manpages manpages-zh manpages-posix manpages-dev info-doc

# CentOS/RHEL
yum install man-pages man-pages-zh-CN info

七、最佳實務建議

  1. 優先用 command --help:快速查參數、範例。
  2. 再用 man command:完整權威參考。
  3. 深入原理用 info command:GNU 軟體特別詳盡。
  4. 忘記指令名用 apropos keyword:關鍵字反查。
  5. 寫腳本查內建用 help builtin:避免混淆外部指令。
copyright © 萬盛學電腦網 all rights reserved