打开手册页并在单个命令中搜索字符串

打开手册页并在单个命令中搜索字符串

我想知道是否有一种方法可以打开特定搜索字符串的手册页,而不是跳转到 chmod 手册页中提到的第一部分,类似于man chmod在vi /a+x( m )。a+xvi +string filename.txt

答案1

试试这个技巧:

man chmod | less +'/a\+x'

或者

man chmod | more +'/a\+x'

符号前有一个反斜杠+,因为后面/扩展正则表达式

答案2

据我所知不是(但@sputnick出来,我知道的不多),但你可以解析它:

man chmod | grep -C 5 'a+x'

我建议使用手册页中实际存在的字符串,例如:

$ man chmod | grep -C 5 set-user-ID
   traversals.

SETUID AND SETGID BITS
   chmod  clears  the  set-group-ID  bit  of a regular file if the file's group ID does not match the
   user's effective group ID or one of the user's supplementary group IDs, unless the user has appro‐
   priate  privileges.   Additional  restrictions  may cause the set-user-ID and set-group-ID bits of
   MODE or RFILE to be ignored.  This behavior depends on the policy and functionality of the  under‐
   lying chmod system call.  When in doubt, check the underlying system behavior.

   chmod preserves a directory's set-user-ID and set-group-ID bits unless you explicitly specify oth‐
   erwise.  You can set or clear the bits with symbolic modes like u+s and g-s, and you can set  (but
   not clear) the bits with a numeric mode.

RESTRICTED DELETION FLAG OR STICKY BIT
   The  restricted  deletion  flag or sticky bit is a single bit, whose interpretation depends on the

答案3

假设您用作less寻呼机(这是现代系统上的默认设置),请将搜索指令添加到环境变量中LESS。这是 的命令行选项列表less。您可以/通过在命令前面加上前缀来传递要执行的 less 命令,例如进行搜索+(就像使用 vi 一样)。

LESS="$LESS +/a\+x" man chmod

这样做的优点man chmod | less "+/a\+x"是不会丢失格式。

也可以看看zmv for zsh:试运行和手册页

相关内容