如何搜尋所有包含某個關鍵字的man檔案?

如何搜尋所有包含某個關鍵字的man檔案?

我想學習如何透過將文件中的內容作為參數來搜尋文件。然後,我可以應用該解決方案來搜尋 Richard Stallman 貢獻的命令(透過手冊頁)。

答案1

man man:

-K, --global-apropos
      Search for text in all manual  pages.   This  is  a  brute-force
      search,  and is likely to take some time; if you can, you should
      specify a section to reduce the number of pages that need to  be
      searched.   Search terms may be simple strings (the default), or
      regular expressions if the --regex option is used.

-w, --where, --location
      Don't actually display  the  manual  pages,  but  do  print  the
      location(s) of the source nroff files that would be formatted.

綜合:

man -wK 'Richard M Stllman'

儘管線上說明頁通常只有Richard Stallman, 兩個單字之間的空格量可變,因此正規表示式可能是合適的:

--regex
      Show all pages with any part of  either  their  names  or  their
      descriptions   matching   each   page   argument  as  a  regular
      expression, as with  apropos(1).   Since  there  is  usually  no
      reasonable  way  to  pick  a  "best"  page  when searching for a
      regular expression, this option implies -a.

所以:

man --regex -wK 'Richard *Stallman' 

答案2

此命令將顯示包含關鍵字的 man 檔案的檔案名稱Stallman

zgrep -l Stallman /usr/share/man/man?/*

我的 15.10 中的輸出開頭為:

/usr/share/man/man1/cat.1.gz
/usr/share/man/man1/comm.1.gz
/usr/share/man/man1/ctags.1.gz
/usr/share/man/man1/ctags.emacs24.1.gz

然後,您可以照常瀏覽,使用man catman comm等。

答案3

此方法不會在整個線上說明頁面中搜尋關鍵字,而是僅搜尋每個線上說明頁的標題和簡短說明。對於您的情況來說,這還不夠,但對於快速尋找某些內容很有用。如果沒有返回想要的結果,則必須使用@菲爾斯夫回答

您可以使用apropos指令可快速搜尋所有已安裝的線上說明頁的標題和說明以尋找關鍵字:

$ apropos chat
chat (8)             - Automated conversational script with a modem
chattr (1)           - change file attributes on a Linux file system
empathy (1)          - GNOME multi-protocol chat and call client

您可以使用下列指令顯示已知線上說明頁的說明whatis

$ whatis empathy
empathy (1)          - GNOME multi-protocol chat and call client

正如我所說,此方法不會搜尋整個線上說明頁正文,因此apropos Stallman不會返回任何內容...

相關內容