首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用grep在手册页中搜索选项?

如何使用grep在手册页中搜索选项?
EN

Ask Ubuntu用户
提问于 2020-10-09 15:31:52
回答 1查看 1.2K关注 0票数 9

我想在一个手册页中搜索特定的选项,如-s-f-l,并且只显示包含这些选项的信息的结果。我尝试了这个命令,希望单引号可以绕过grep接收选项:

代码语言:javascript
复制
man --pager=cat some_man_page_here | grep '-option_here'

我也尝试过\,但是grep给了我一个语法错误:

代码语言:javascript
复制
Usage: grep [OPTION]... PATTERNS [FILE]...
Try 'grep --help' for more information.

我只想知道是否有一种方法可以使用grep搜索手册中的选项。我目前正在使用终端顶部栏上的“查找”按钮,但为了提高效率,我希望能够使用grep

EN

回答 1

Ask Ubuntu用户

回答已采纳

发布于 2020-10-09 15:39:51

这个在你的案子里有用吗?

代码语言:javascript
复制
$ man ls | grep -- '--a'
     -a, --all
     -A, --almost-all
     --author

一个更详细(希望更清楚)的命令示例:

代码语言:javascript
复制
$ man shutdown | grep -- '-'
       shutdown - Halt, power-off or reboot the machine
       shutdown may be used to halt, power-off or reboot the machine.
       logged-in users before going down.
       --help
       -H, --halt
       -P, --poweroff
           Power-off the machine (the default).
       -r, --reboot
       -h
           Equivalent to --poweroff, unless --halt is specified.
       -k
           Do not halt, power-off, reboot, just write wall message.
       --no-wall
           Do not send wall message before halt, power-off, reboot.
       -c
       On success, 0 is returned, a non-zero failure code otherwise.

编辑:

作为格伦·杰克曼在下面评论 (非常有用):

将结果缩小到以连字符开头的一行: grep '^[]*-‘--

测试运行:

代码语言:javascript
复制
$ man shutdown | grep -- '-' | grep '^[[:space:]]*-'
       --help
       -H, --halt
       -P, --poweroff
       -r, --reboot
       -h
       -k

很明显,在Linux中也可以使用<>。

外部链接:

在Unix上对手册页进行全文搜索

票数 8
EN
页面原文内容由Ask Ubuntu提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://askubuntu.com/questions/1281432

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档