我想在一个手册页中搜索特定的选项,如-s、-f、-l,并且只显示包含这些选项的信息的结果。我尝试了这个命令,希望单引号可以绕过grep接收选项:
man --pager=cat some_man_page_here | grep '-option_here'我也尝试过\,但是grep给了我一个语法错误:
Usage: grep [OPTION]... PATTERNS [FILE]...
Try 'grep --help' for more information.我只想知道是否有一种方法可以使用grep搜索手册中的选项。我目前正在使用终端顶部栏上的“查找”按钮,但为了提高效率,我希望能够使用grep。
发布于 2020-10-09 15:39:51
这个在你的案子里有用吗?
$ man ls | grep -- '--a'
-a, --all
-A, --almost-all
--author一个更详细(希望更清楚)的命令示例:
$ 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 '^[]*-‘--
测试运行:
$ man shutdown | grep -- '-' | grep '^[[:space:]]*-'
--help
-H, --halt
-P, --poweroff
-r, --reboot
-h
-k很明显,在Linux中也可以使用<>。
外部链接:
https://askubuntu.com/questions/1281432
复制相似问题