從「人」開始:幾個問題

從「人」開始:幾個問題

我和男人之間有問題:

  1. 如何顯示手冊頁的各個部分?如何找出手冊頁提供了哪些部分?根據是man man -S我需要取得手冊頁可用「部分」清單的參數。但是,如果我嘗試顯示gitlspwdwith 的可用部分:man -S git。我希望有一個列表,但我得到的只是:您想要什麼手冊頁?

  2. 我還有第二個問題:如何顯示手冊頁的簡短版本/預覽?解決這個問題也是我的任務。我找不到一個聽起來像我想做的事情的參數。

PS:我在 MacOS Sierra 上使用 shell

答案1

簡單的答案:

手冊頁沒有包含部分;部分包含手冊頁。

這是指您正在談論的編號部分。可以有兩個同名的手冊頁,但位於兩個不同(編號)的部分,例如,printf.手冊printf(1)頁涵蓋了命令列工具。手冊printf(3)頁涵蓋了 C 函數呼叫。

您可以透過執行以下命令按順序查看兩個手冊頁:

man -a printf

當你退出第一個時,你會看到第二個。

您可以透過執行以下命令來查看它出現在哪些部分,而無需打開其中任何一個部分:

man -aw printf

除了編號部分之外其中手冊頁存在,各手冊頁也被劃分視覺上具有單獨的標題和子標題,例如「名稱」、「摘要」、「說明」等。

這些都是稱為“節”,但“節”一詞的用法與上述編號的節明顯不同。

答案2

過去,線上手冊(「線上」與「印刷」相對)曾經有八個部分,但後來添加了更多內容。這些部分是 1, 2, ..., 8,因此您可以輸入類似的內容

man -S 4 xyz

取得第 4 節中 xyz 的手冊頁。

實際上,只有當多個部分中有相同關鍵字的手冊頁時,指定一個部分才重要。

例如:

man printf

產量

PRINTF(1)                                                         User Commands

NAME
       printf - format and print data

SYNOPSIS
       printf FORMAT [ARGUMENT]...
       printf OPTION

DESCRIPTION
       Print ARGUMENT(s) according to FORMAT, or execute according to OPTION
...

儘管

man -S 3 printf

產量

PRINTF(3)                                                   Linux Programmer's Manual

NAME
       printf, fprintf, dprintf, sprintf, snprintf, vprintf, vfprintf, vdprintf, vsprintf, vsnprintf - formatted output conversion

SYNOPSIS
       #include <stdio.h>

       int printf(const char *format, ...);
       int fprintf(FILE *stream, const char *format, ...);
       int dprintf(int fd, const char *format, ...);
       int sprintf(char *str, const char *format, ...);
       int snprintf(char *str, size_t size, const char *format, ...);
...

嘗試man -S x intro使用x= 1,2,3,... 來取得各個部分的介紹。

有時你會發現類似這樣的陳述:...fork(2)用於建立新流程;這之後通常是execl(3)...這表示 的手冊頁fork位於第 2 部分,而 的手冊頁execl位於第 3 部分。

如何顯示手冊頁的簡短版本/預覽?

我不確定你的意思是什麼。man不提供類似Get-HelpPowerShell 中的功能。whatis給你一個非常簡短的描述,例如

whatis man
man                  (1)  - format and display the on-line manual pages
man                  (1p)  - display system documentation
man                  (7)  - macros to format man pages
man []               (1)  - format and display the on-line manual pages
man []               (1p)  - display system documentation
man []               (7)  - macros to format man pages
man []               (7)  - pages - conventions for writing Linux man pages
man-pages            (7)  - conventions for writing Linux man pages
man.conf []          (5)  - configuration data for man
man.conf [man]       (5)  - configuration data for man

答案3

-S 參數不會執行您想要的操作。它用於指定您要查看哪些類別的手冊頁。

我不知道是否有一種自動顯示手冊頁各部分的方法。我會使用 grep/sed/awk 等工具來解析手冊頁並提取我感興趣的文本,即:

man ls|grep -v -e '^$' -e '^[[:space:]]'

上面的程式碼不是完整的解決方案。其一,它也列印手冊頁的頁首和頁尾。我相信您可以對其進行修改以完全滿足您的要求,或提出更好的實現;)

同樣,取得手冊頁「預覽」的請求可以透過以下方式輕鬆完成管道輸出人變成另一種工具。我會推薦為了那個任務。

答案4

[1.]

我希望有一個列表,但我得到的只是:您想要什麼手冊頁?

-S不用於顯示部分列表,而是要求您傳遞部分列表您想要的部分搜尋順序。例如

xb@dnxb:/tmp$ man -S=7,6,5,4,3,2 ls
No manual entry for ls
See 'man 7 undocumented' for help when manual pages are not available.
xb@dnxb:/tmp$ 

上圖-S=7,6,5,4,3,2顯示了該清單中從左到右的部分搜尋順序。如果手冊ls包含第7節,它會顯示它。如果沒有,它將嘗試搜尋第 6 節,依此類推。如果此清單末尾不存在任何部分,則會顯示“No Manual Entry for ls”即使第 1 節存在。但這是有效的,因為清單中的第 1 部分:

xb@dnxb:/tmp$ man -S=7,6,5,4,3,2,1 ls
xb@dnxb:/tmp$ 

試試這兩個來證明 的搜尋順序-S是從左到右:

xb@dnxb:/tmp$ man -S 1,1posix ls
xb@dnxb:/tmp$ man -S 1posix,1 ls
xb@dnxb:/tmp$ 

您也可以簡單地傳遞確切的部分,而無需-S

xb@dnxb:/tmp$ man 5 ls
No manual entry for ls in section 5
See 'man 7 undocumented' for help when manual pages are not available.
xb@dnxb:/tmp$ man 1posix ls
xb@dnxb:/tmp$

預設的排序可以在這裡找到(這個檔案路徑在 中描述man man),搜尋順序從左到右:

xb@dnxb:/tmp$ \grep SECTION /etc/manpath.config
# the default is 1, n, l, 8, 3, 0, 2, 5, 4, 9, 6, 7. Multiple SECTION
SECTION         1 n l 8 3 2 3posix 3pm 3perl 5 4 9 6 7
xb@dnxb:/tmp$ 

如何顯示手冊頁的各個部分?如何找出手冊頁提供了哪些部分?

使用apropos [-e]whatis、 或man -k

xb@dnxb:/tmp$ apropos statvfs #OR man -k statvfs
fstatvfs (2)         - get filesystem statistics
fstatvfs (3)         - get filesystem statistics
fstatvfs (3posix)    - get file system information
statvfs (2)          - get filesystem statistics
statvfs (3)          - get filesystem statistics
statvfs (3posix)     - get file system information
statvfs.h (7posix)   - VFS File System information structure
sys_statvfs.h (7posix) - VFS File System information structure
xb@dnxb:/tmp$ apropos -e statvfs #OR whatis statvfs
statvfs (2)          - get filesystem statistics
statvfs (3)          - get filesystem statistics
statvfs (3posix)     - get file system information
xb@dnxb:/tmp$ 

[2.]

如何顯示手冊頁的簡短版本/預覽?

我總是習慣--help查看手冊的簡短版本(免責聲明:不完全等同),例如:

xb@dnxb:/tmp$ mplayer --help
Usage:   mplayer [options] [url|path/]filename

Basic options: (complete list in the man page)
 -vo <drv>        select video output driver ('-vo help' for a list)
 -ao <drv>        select audio output driver ('-ao help' for a list)
 vcd://<trackno>  play (S)VCD (Super Video CD) track (raw device, no mount)
 dvd://<titleno>  play DVD title from device instead of plain file
 -alang/-slang    select DVD audio/subtitle language (by 2-char country code)
 -ss <position>   seek to given (seconds or hh:mm:ss) position
 -nosound         do not play sound
 -fs              fullscreen playback (or -vm, -zoom, details in the man page)
 -x <x> -y <y>    set display resolution (for use with -vm or -zoom)
 -sub <file>      specify subtitle file to use (also see -subfps, -subdelay)
 -playlist <file> specify playlist file
 -vid x -aid y    select video (x) and audio (y) stream to play
 -fps x -srate y  change video (x fps) and audio (y Hz) rate
 -pp <quality>    enable postprocessing filter (details in the man page)
 -framedrop       enable frame dropping (for slow machines)

Basic keys: (complete list in the man page, also check input.conf)
 <-  or  ->       seek backward/forward 10 seconds
 down or up       seek backward/forward  1 minute
 pgdown or pgup   seek backward/forward 10 minutes
 < or >           step backward/forward in playlist
 p or SPACE       pause movie (press any key to continue)
 q or ESC         stop playing and quit program
 + or -           adjust audio delay by +/- 0.1 second
 o                cycle OSD mode:  none / seekbar / seekbar + timer
 * or /           increase or decrease PCM volume
 x or z           adjust subtitle delay by +/- 0.1 second
 r or t           adjust subtitle position up/down, also see -vf expand

 * * * SEE THE MAN PAGE FOR DETAILS, FURTHER (ADVANCED) OPTIONS AND KEYS * * *

MPlayer 1.3.0 (Debian), built with gcc-5.4.0 (C) 2000-2016 MPlayer Team
xb@dnxb:/tmp$ 

相關內容