我想学习如何通过将文件内容作为参数来搜索文件。然后我可以应用该解决方案来搜索 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 cat
、man 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
不会返回任何内容...