有没有任何方法可以对手册进行全文搜索,并从像apropos(1)这样的控制台获取相关手册的名称和描述?
您可以使用man -K全文搜索手册的内容。但是有三个问题:
man -K没有向控制台显示第一个结果的标题。man -K只显示了如下所示的手册标题:--Man-- next: ansible(1) [ view (return) | skip (Ctrl-D) | quit (Ctrl-C) ]man -K要求Ctrl-D跳过查看手册页的内容。因此,不能使用yes(1)将响应传递给man -K。发布于 2021-07-25 14:38:38
可能有一种更简单的方法,但我发现man -K可以与-w组合,以打印包含搜索条件的文件的路径,例如,您可以将它与lexgrog结合起来提取whatis信息:
$ man -Kws1 apropos | sort -u | xargs -rd '\n' lexgrog | perl -pe's/.*?: "(.*)"/$1/'
apropos - search the manual page names and descriptions
emacs - GNU project Emacs editor
groffer - display groff files and man pages on X and tty
info - read Info documents
lexgrog - parse header information in man pages
man - an interface to the system reference manuals
manpath - determine search path for manual pages
scanimage - scan an image
whatis - display one-line manual page descriptions
xman - Manual page display program for the X Window System(这里假设GNU xargs是-r和-d选项,尽管后者不太可能是必要的)
您可以将其转换为full-apropos脚本或函数,如:
#! /bin/sh -
man -Kw "$@" |
sort -u |
xargs -rd '\n' lexgrog |
perl -pe's/.*?: "(.*)"/$1/'不过,我们漏掉了男性部分的信息。因为这是在文件的路径中,所以我们可以将其添加回如下所示:
#! /bin/sh -
man -Kw "$@" |
sort -u |
while IFS= read -r file; do
section=${file%/*}
section=${section##*/man}
lexgrog -- "$file" |
perl -spe's/.*?: "(.*)"/$1/; s/ - / ($s)A9/' -- "-s=$section"
donehttps://unix.stackexchange.com/questions/659819
复制相似问题