Answers:
所使用的默认寻呼机man
是less
。您可以通过环境变量less
传递直接理解的ERE(扩展正则表达式)搜索模式LESS
,在这种情况下,您应该执行以下操作:
LESS='+/-f' man apt-get
这与/-f
做完之后通过完全一样man apt-get
。
现在,这将突出显示所有-f
S IN的man
页面,直接跳转到所需的一个IE选项中-f
,你可以利用ERE只匹配,与空格/制表符开头的行,其次是-f
:
LESS='+/^[[:blank:]]+-f' man apt-get
尽管这可以在此处完成,但仍可能不适用于所有页面,因为这将与-f
在初始空格/制表符之后开始的任何内容匹配。在这些情况下,请稍微调整一下模式以满足您的需求。
您可以创建一个微型函数来传递搜索模式,并将man
页面作为参数进行查找(如果您经常这样做)。
使用sed
显示的选项用连字符开始的整个段落。要-f
通过运行单个命令立即显示该选项的整个段落,请使用:
man apt-get | sed -n '/-f,/,/^$/p'
-f-,--no-f, -f=no or several other variations.
-f, --fix-broken
Fix; attempt to correct a system with broken dependencies in place.
This option, when used with install/remove, can omit any packages
to permit APT to deduce a likely solution. If packages are
specified, these have to completely correct the problem. The option
is sometimes necessary when running APT for the first time; APT
itself does not allow broken package dependencies to exist on a
system. It is possible that a system's dependency structure can be
so corrupt as to require manual intervention (which usually means
using dpkg --remove to eliminate some of the offending packages).
Use of this option together with -m may produce an error in some
situations. Configuration Item: APT::Get::Fix-Broken.
这将返回-f
man中选项的整个段落,apt-get
但是可以通过消除逗号来改进上述命令-f
,使其更普遍地起作用,如下所示:
man apt-get | sed -n '/-f/,/^$/p'
这将返回多个段落,其中大部分您都不希望阅读。通过阅读多个段落的第一行,您可以看到您只想显示包含该-f, --fix-broken
选项的段落。执行以下操作:
man apt-get | sed -n '/--fix-broken/,/^$/p'
-f, --fix-broken
Fix; attempt to correct a system with broken dependencies in place.
This option, when used with install/remove, can omit any packages
to permit APT to deduce a likely solution. If packages are
specified, these have to completely correct the problem. The option
is sometimes necessary when running APT for the first time; APT
itself does not allow broken package dependencies to exist on a
system. It is possible that a system's dependency structure can be
so corrupt as to require manual intervention (which usually means
using dpkg --remove to eliminate some of the offending packages).
Use of this option together with -m may produce an error in some
situations. Configuration Item: APT::Get::Fix-Broken.
这仅返回您要读取的输出。此方法适用于以连字符开头的任何其他选项,并且通常也可用于搜索其他命令中以连字符开头的选项apt-get
。
如果一个段落的描述没有提供足够的信息,则以下命令将显示与上一个命令相同的第一段,并在其后显示下一段。
LESS='+/^[[:space:]]*-f' man apt-get
该命令的结果表明下一段不是很有趣,但是对于某些选项,下一段也很有趣。这就是为什么这也是一个有用的命令要知道的原因。