问题:
我想在手册页中搜索特定的选项,如-s
,-f
,-l
,并且只显示包含这些选项的信息的结果,
man --pager=cat some_man_page_here | grep '-option_here'
我尝试过,但是grep
给我一个语法错误:
Usage: grep [OPTION]... PATTERNS [FILE]...
Try 'grep --help' for more information.
答案1:
$ 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 '^[[:space:]]*-' -
测试运行:
$ man shutdown | grep -- '-' | grep '^[[:space:]]*-'
--help
-H, --halt
-P, --poweroff
-r, --reboot
-h
-k
相关文章