Command-Line

如何列印手冊的一部分(人)?

  • April 5, 2022

從終端,如何列印以輸出結果的特定部分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

[...]

從 Meta引用我自己的文章:

連結到手冊頁

我已經有一個喜歡的方法,你可以在less手冊頁的兩個地方閱讀:

LESS='+/\+cmd' man less

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

(看看我在那裡做了什麼?)

您可以使用程序-P標誌man來使用尋呼機來顯示頁面。例如,您可以使用less帶有標誌的分頁程序-p來搜尋ERROR手冊頁內行首發生的模式:

man -P 'less -p ^ERRORS' symlink

這將打開手冊頁symlink並直接跳轉到其中的ERRORS部分。

引用自:https://unix.stackexchange.com/questions/283507