简体   繁体   English

如何搜索 Linux 手册页(例如使用 grep)

[英]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?关于如何将grepman一起使用的任何想法,或者更一般地关于如何搜索特定行的手册页的任何想法?

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 )并最后按ENTERman页中进行搜索。 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.

相关问题 使用 Linux 实用程序(例如 grep)搜索文件 0x1F(单位分隔符) - Search in files 0x1F (Unit Separator) using Linux utilities (e.g. grep) 包含例如 git-branch(1) 的手册页的含义是什么 - What is the meaning of man pages contaning e.g. git-branch(1) 如何在 Linux 上获得总体 RAM 使用率(例如 57%) - How to get overall RAM usage (e.g. 57%) on Linux 如何在 Linux 上获取整体 CPU 使用率(例如 57%) - How to get overall CPU usage (e.g. 57%) on Linux 在查看手册页时,如何查看其加载目录? (例如,本地份额与系统份额的确定)? - While viewing a man page, how can I see the directory it was loaded from? (e.g., for local share vs system share determination)? 如何限制Linux上的进程内存利用率(例如使用BSD :: Resource) - How to limit process memory utilization on Linux (e.g. using BSD::Resource) 一个演示cmd.exe和Linux shell(例如bash),定界参数的AC程序? - A C program demonstrating how cmd.exe and a linux shell e.g. bash, delimit parameters? 从git导入代码到Linux ide,例如kdevelop - Import code from git to Linux ide e.g. kdevelop 在 unix/linux 命令行中定义函数(例如 BASH) - Define function in unix/linux command line (e.g. BASH) Linux中的批量适合图像(例如GIMP) - Batch fit image in Linux (e.g. GIMP)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM