[英]How to search Linux man pages (e.g. with grep)
I'm looking for information on the -X
option of curl
.我正在寻找有关
curl
的-X
选项的信息。 However, the documentation is quite lengthy and I have to scroll down for quite a long time to get to this option.但是,文档很长,我必须向下滚动很长时间才能找到此选项。 Instead, I'd like to do something like
相反,我想做类似的事情
man curl | grep -X
to get the line containing "-X".获取包含“-X”的行。 (I would also do this in conjunction with the option
-A 10
to get the 10 lines after the match). (我也会结合选项
-A 10
来执行此操作以在比赛后获得 10 行)。 However, if I try this I get但是,如果我尝试这样做,我会得到
grep: option requires an argument -- 'X'
Usage: grep [OPTION]... PATTERN [FILE]...
Try 'grep --help' for more information.
Any ideas on how to use grep
together with man
, or more generally on how to search man pages for specific lines?关于如何将
grep
与man
一起使用的任何想法,或者更一般地关于如何搜索特定行的手册页的任何想法?
You have to tell grep that -X
is not an option, but the pattern to look for:您必须告诉 grep
-X
不是一个选项,而是要查找的模式:
man curl | grep -- '-X'
--
indicates the end of options. --
表示选项结束。 Without it, grep thinks that -X
is an option.没有它,grep 认为
-X
是一个选项。
Alternatively, you can use -e
to indicate that what follows is a pattern:或者,您可以使用
-e
来指示接下来是一个模式:
man curl | grep -e '-X'
If you want to see the complete man page but skip directly to the first occurrence of -X
, you can use a command line option to less
:如果您想查看完整的手册页但直接跳到
-X
的第一次出现,您可以使用命令行选项less
:
man curl | less +/-X
Typing N repeatedly then takes you to the following occurrences.重复键入N然后将带您到以下事件。
man
will implicitly open in less
if you have it installed. man
会隐在打开less
,如果你安装了它。 So maybe you could read man page for less
.所以也许你可以阅读 man page for
less
。
less
actually supports search on it's own. less
实际上支持它自己的搜索。 Just press /
and write what you wanna search and enter
.只需按
/
并写下您想要搜索的内容并enter
。 Use n
to skip to next occurrence and N
for previous.使用
n
跳到下一发生N
对于以前。
On most Linux systems, the default pager used by man
is less
.在大多数 Linux 系统上,
man
使用的默认寻呼机是less
。
If that is the case, you can search in a man
page using the / (slash) key followed by a query (here -X
) and finally hit ENTER .如果是这种情况,您可以使用/ (斜线)键后跟查询(此处为
-X
)并最后按ENTER在man
页中进行搜索。 It will highlight all cases of -X
.它将突出显示
-X
所有情况。 It is of course possible that the first "hit" is not the one you want.当然,第一个“命中”可能不是您想要的。 In that case you can hit N to go to the
N ext hit and so browse through the entire document.
在这种情况下,你可以打了N去到N内线命中,并在整个文档中,以便浏览。 In case you have jumped too far, you can use Shift + N to jump back to the previous hit.
如果你跳得太远,你可以使用Shift + N跳回上一个命中。
This is not really an answer to the question how to handle this with grep
, but it is simply a way to efficiently search in man
.这不是如何用
grep
处理这个问题的真正答案,但它只是一种在man
有效搜索的方法。
You can read the man
page of less
( man less
) for further tricks on how to effectively use less
to improve your experience with man
pages.您可以阅读
less
( man less
) 的man
页,了解有关如何有效使用less
来改善man
页体验的更多技巧。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.