链接到手册页

链接到手册页

从终端,如何打印以输出结果的特定部分man something

例如,如果我想要获取一些关于 C 函数 write 的返回值的信息,我希望看到如下内容:

RETURN VALUE
       On  success,  the  number  of bytes written is returned (zero indicates
       nothing was written).  It is not an error if  this  number  is  smaller
       than the number of bytes requested; this may happen for example because
       the disk device was filled.  See also NOTES.

       On error, -1 is returned, and errno is set appropriately.

       If count is zero and fd refers to a  regular  file,  then  write()  may
       return  a failure status if one of the errors below is detected.  If no
       errors are detected, or error detection is not  performed,  0  will  be
       returned  without  causing  any  other effect.  If count is zero and fd
       refers to a file other than a regular file, the results are not  speci‐
       fied.

ERRORS
       EAGAIN The  file descriptor fd refers to a file other than a socket and
          has been marked nonblocking (O_NONBLOCK), and  the  write  would
          block.  See open(2) for further details on the O_NONBLOCK flag.

       EAGAIN or EWOULDBLOCK
          The  file  descriptor  fd refers to a socket and has been marked
          nonblocking   (O_NONBLOCK),   and   the   write   would   block.
[...]

代替:

WRITE(2)                   Linux Programmer's Manual                  WRITE(2)

NAME
       write - write to a file descriptor

SYNOPSIS
       #include <unistd.h>

       ssize_t write(int fd, const void *buf, size_t count);

DESCRIPTION
       write()  writes  up  to  count bytes from the buffer pointed buf to the
       file referred to by the file descriptor fd.

       The number of bytes written may be less than  count  if,  for  example,
       there  is  insufficient space on the underlying physical medium, or the
       RLIMIT_FSIZE resource limit is encountered (see setrlimit(2)),  or  the
       call was interrupted by a signal handler after having written less than
       count bytes.  (See also pipe(7).)

       For a seekable file (i.e., one to which lseek(2) may  be  applied,  for
       example,  a  regular file) writing takes place at the current file off‐
       set, and the file offset is incremented by the number of bytes actually

[...]

答案1

您可以使用程序-P标志man来使用寻呼机来显示页面。例如,您可以使用less带有标志的分页程序-p来搜索ERROR手册页内行开头发生的模式:

man -P 'less -p ^ERRORS' symlink

这将打开 的手册页symlink并直接跳转到该ERRORS部分。

答案2

去引用我自己在 Meta 上发表的帖子:

链接到手册页

我已经有一个最喜欢的方法,您可以在less手册页的两个地方阅读该方法:

LESS='+/\+cmd' man less

LESS='+/LESS[[:space:]]*Options' man less

(看看我在那里做了什么?)

答案3

例如,如果您只是打开一个联机帮助页,例如:
man cowsay
您可以键入:来查找并跳转到 AUTHOR 行。
/AUTHOR
或者:在联机帮助页中
/myFunction
查找 的实例myFunction
(如果有多个实例,可以按n转到下一个实例)

另外,如果您在手册页中,您可以键入h并获取 less 命令的摘要,如下所示。我在我认为与你相关的部分之后将它们剪掉了,但还有更多。

                  Less 命令总结

      标有 * 的命令前面可以带有数字 N。
      括号中的注释指示给定 N 时的行为。

  h H 显示此帮助。
  q :q Q :Q ZZ 退出。
 -------------------------------------------------- ------------------------

                           移动

  e ^E j ^N CR * 前进一行(或 N 行)。
  y ^Y k ^K ^P * 向后一行(或N行)。
  f ^F ^V SPACE * 向前一个窗口(或 N 行)。
  b ^B ESC-v * 向后一个窗口(或 N 行)。
  z * 前进一个窗口(并将窗口设置为N)。
  w * 向后一窗口(并将窗口设置为 N)。
  ESC-SPACE * 前进一个窗口,但不要停在文件末尾。
  d ^D * 前进一个半窗(并将半窗设置为 N)。
  u ^U * 向后一个半窗(并将半窗设置为N)。
  ESC-) RightArrow * 左半个屏幕宽度(或 N 个位置)。
  ESC-( 左箭头 * 右半个屏幕宽度(或 N 个位置)。
  F 永远向前;就像“尾-f”。
  r ^R ^L 重新绘制屏幕。
  R 重新绘制屏幕,​​丢弃缓冲的输入。
        -------------------------------------------------- -
        默认“窗口”是屏幕高度。
        默认“半窗口”是屏幕高度的一半。
 -------------------------------------------------- ------------------------

                          搜索

  /pattern * 向前搜索(第 N 个)匹配行。
  ?pattern * 向后搜索(第 N 个)匹配行。
  n * 重复先前的搜索(第 N 次出现)。
  N * 反向重复先前的搜索。
  ESC-n * 重复先前的搜索,跨文件。
  ESC-N * 重复先前的搜索,反转目录。 &跨文件。
  ESC-u 撤消(切换)搜索突出显示。
  &pattern * 仅显示匹配的行
        -------------------------------------------------- -
        搜索模式可以通过以下一项或多项进行修改:
        ^N 或 !搜索不匹配的行。
        ^E 或 * 搜索多个文件(通过文件末尾)。
        ^F 或 @ 从第一个文件 (对于 /) 或最后一个文件 (对于 ?) 开始搜索。
        ^K 突出显示匹配项,但不要移动(保持位置)。
        ^R 不要使用正则表达式。
 -------------------------------------------------- ------------------------

                           跳跃

  g ESC-> * 转到文件的最后一行(或第 N 行)。
  p % * 转到文件开头(或进入文件的 N%)。

如果您只是想更轻松地阅读大型手册页,这应该可行。

答案4

照顾树木你应该重新考虑是否打印全部或部分手册页,特别是每隔几个月就会更改的手册页。

相反,正如其他答案中所建议的,您可以(学习)使用寻呼机(例如less)来回搜索您需要的信息。通常,手册页的结构可以帮助您更轻松地找到它。

另外,有些程序允许您在“内部”打开手册页,例如 Emacs:您可以在其中使用“MX man“ (或者 ”MX woman") 命令打开手册页,然后使用所有编辑器功能在其中导航(Emacs 也有一个print-region功能,但解释该功能与本答案无关)。

相关内容