
從終端,如何列印以輸出結果的特定部分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
功能,但解釋該功能與本答案無關)。