尋找所有帶有 wh 的指令,透過手冊頁中的部分關鍵字查找

尋找所有帶有 wh 的指令,透過手冊頁中的部分關鍵字查找

我想查找以 . 開頭的命令的所有手冊頁wh。但我不明白為什麼以下關鍵字不起作用。

  man -f "wh"

另外如果我把

  man chmod

在 的手冊頁中chmod,它有“符號”一詞,所以我把

  man -f "symbolic"

chmod命令不顯示在結果中。

簡而言之,如何透過字內內容尋找/搜尋命令或命令描述?我知道如何在獲得手冊頁後使用/字符查找特定單詞,但我想使用搜尋字詞查找所有手冊頁。

答案1

您可以使用該-k開關來尋找包含wh其名稱或簡短描述的所有手冊頁。然後只需 grep 尋找以 開頭的那些wh。該命令apropos相當於man -k.

例子

$ man -k wh | grep "^wh"
what (1p)            - identify SCCS files (DEVELOPMENT)
whatis (1)           - display manual page descriptions
whereis (1)          - locate the binary, source, and manual page files for a command
which (1)            - shows the full path of (shell) commands.
while (n)            - Execute script repeatedly as long as a condition is met
whiptail (1)         - display dialog boxes from shell scripts
whirlwindwarp (6x)   - crazy moving stars
whline (3x)          - create curses borders, horizontal and vertical lines
whline_set (3x)      - create curses borders or lines using complex characters and renditions
who (1)              - show who is logged on
who (1p)             - display who is on the system
whoami (1)           - print effective userid
whois (1)            - client for the whois service

搜尋手冊頁

如果您決定透過全文搜尋來搜尋手冊頁,則可以使用該-K開關。那是大寫的K。

例子

$ man -w -K symbolic | head -10
/usr/local/share/man/man1/mimeopen.1
/usr/local/share/man/man1/mimetype.1
/usr/local/share/man/man1/ptksh.1
/usr/share/man/man1/as.1.gz
/usr/share/man/man1/atop.1.gz
/usr/share/man/man1/atopsar.1.gz
/usr/share/man/man1/attr.1.gz
/usr/share/man/man1/autoreconf.1.gz
/usr/share/man/man1/bakefilize.1.gz
/usr/share/man/man1/bash.1.gz

不過,此方法不會提供您手冊頁的名稱或簡短描述。它僅顯示儲存手冊頁的檔案的實際名稱,通常是命令的名稱。

答案2

man -f wh(與 同義詞whatis)顯示指令 的簡短(一行)描述wh。此標誌-f指示man僅顯示第一行而不是整個頁面。那不是你所追求的。

該指令apropos wh(與 同義詞man -k wh)列出其簡短描述包含字串 的手冊頁wh。如果您想要將簡短描述中的搜尋與指令名稱上的模式結合起來,可以過濾aproposwith的結果grep。若要限制為使用者命令(即第 1 節)且不顯示管理員命令、C 庫函數等,請傳遞-S 1.如果您同時需要使用者命令和管理員命令,請傳遞-S 1:8

apropos symbolic | grep '^wh'

man若要使用 mandb( Linux 上最常見的實作)搜尋整個手冊頁,請使用-K(大寫K,而不是小寫kapropos。如果您安裝了很多手冊頁,這可能需要很長時間;考慮傳遞--regex選項以將搜尋限制為單行描述與正規表示式相符的手冊頁。

man -K -S 1:8 --regex 'change.*file' symbolic

答案3

man -k '^symbolic$'

這將列出應用程式名稱以及符號一詞所在的頁碼。如果您想要任何以符號開頭的內容,請去掉 $。

相關內容