Man page (简体中文)

From ArchWiki
Revision as of 10:49, 8 May 2011 by Cuihao (talk | contribs) (搜索手册页)
Jump to navigation Jump to search

This template has only maintenance purposes. For linking to local translations please use interlanguage links, see Help:i18n#Interlanguage links.


Local languages: Català – Dansk – English – Español – Esperanto – Hrvatski – Indonesia – Italiano – Lietuviškai – Magyar – Nederlands – Norsk Bokmål – Polski – Português – Slovenský – Česky – Ελληνικά – Български – Русский – Српски – Українська – עברית – العربية – ไทย – 日本語 – 正體中文 – 简体中文 – 한국어


External languages (all articles in these languages should be moved to the external wiki): Deutsch – Français – Română – Suomi – Svenska – Tiếng Việt – Türkçe – فارسی

Template:Article summary start Template:Article summary text Template:Article summary end

man手册页(manual pages,“手册”),是类UNIX系统最重要的手册工具。多数类UNIX都预装了它,这也包括Arch。使用man手册页的命令是:Template:Codeline

man手册页被设计成“自足”的文档库,即论述相关问题时无法通过类似超链接的东西引向其他手册页。GNU正努力改变原始的man手册页格式。

阅读手册页

通过以下命令阅读man手册页:

$ man 手册名

man手册页分为下面几个部分:

  1. 普通命令
  2. 内核提供的系统调用
  3. 库调用(C库函数)
  4. 特殊文件(大多在/dev目录下)和设备
  5. 文件格式规范
  6. 游戏
  7. 杂项(及其规范)
  8. 系统管理命令(通常需要root权限)和守护进程

man手册页通过名称和所属分类标识。有些不同分类的man手册页名字可能相同,比如 man(1) 和 man(7),这时需要额外指明分类以访问需要的手册。例如:

$ man 5 passwd

会显示有关文件Template:Codeline,而非命令 Template:Codeline,的内容。

通过Template:Codeline命令,可以只显示需要的man手册页的简要信息。如果只是想获取对命令 ls 的简要说明,使用以下命令:

$ whatis ls

然后会得到输出:“list directory contents.”(“列目录内容”)。

格式

所有man手册页都按照以下标准格式组织:

  • NAME - 手册叙述对象名称,及简要描述。
  • SYNOPSIS - 命令参数格式,或者函数调用格式等。
  • DESCRIPTION - 对叙述对象更加详细的描述。
  • EXAMPLES - 由浅入深的使用示例。
  • OPTIONS - 命令行或者函数调用参数的意义。
  • EXIT STATUS - 不同返回(退出)代码的含义。
  • FILES - 与叙述对象相关的文件。
  • BUGS - 已知的bug。
  • SEE ALSO - 相关内容列表。
  • AUTHOR, HISTORY, COPYRIGHT, LICENSE, WARRANTY - 历史、版权、编者信息。

搜索手册页

如果用户压根儿不知道要查阅的手册的名称,该怎么办呢?没事,通过 Template:Codeline 或者 Template:Codeline 参数就可以按给定关键词搜索相关手册。例如,要查阅有关密码的手册(“password”):

$ man -k password

或者:

$ man --apropos password

还可以直接使用 Template:Codeline 命令:

$ apropos password

关键字可以使用正则表达式。

彩色显示

For some users, color-enabled man pages allow for a clearer presentation and easier digestion of the content. Given that users new to Linux are prone to spend a considerable amount of time familiarizing themselves with basic userspace tools, setting up a comfortable environment is a necessity to most.

There are two prevalent methods for achieving colored man pages: using Template:Codeline, or opting for Template:Codeline. The former is simpler to configure, at the expense of the advanced functionality that is native to Template:Codeline.

方法一:使用most

Install Template:Package Official using pacman:

# pacman -S most

This is similar to Template:Codeline and Template:Codeline, yet allows rendering colored text in an easier way.

Edit Template:Filename, uncomment the pager definition and change it to:

DEFINE     pager     most -s

Test the new setup by typing:

$ man whatever_man_page

Modifying the color values requires editing Template:Filename (creating the file if it is not present) or editing Template:Filename for system-wide changes. Example Template:Filename:

% Color settings
color normal lightgray black
color status yellow blue
color underline yellow black
color overstrike brightblue black

Another example showing keybindings similar to Template:Codeline (jump to line is set to 'J'):

% less-like keybindings
unsetkey "^K"
unsetkey "g"
unsetkey "G"
unsetkey ":"

setkey next_file ":n"
setkey find_file ":e"
setkey next_file ":p"
setkey toggle_options ":o"
setkey toggle_case ":c"
setkey delete_file ":d"
setkey exit ":q"

setkey bob "g"
setkey eob "G"
setkey down "e"
setkey down "E"
setkey down "j"
setkey down "^N"
setkey up "y"
setkey up "^Y"
setkey up "k"
setkey up "^P"
setkey up "^K"
setkey page_down "f"
setkey page_down "^F"
setkey page_up "b"
setkey page_up "^B"
setkey other_window "z"
setkey other_window "w"
setkey search_backward "?"
setkey bob "p"
setkey goto_mark "'"
setkey find_file "E"
setkey edit "v"

方法二:使用less

Source: nion's blog - less colors for man pages

Alternatively, getting an approximate coloured result in manual pages with Template:Codeline is also a possibility. This method has the advantage that Template:Codeline has a bigger feature set than Template:Codeline, and that might be the preference for advanced users.

Add the following to a shell configuration file. For Bash it would be Template:Filename:

man() {
	env \
		LESS_TERMCAP_mb=$(printf "\e[1;37m") \
		LESS_TERMCAP_md=$(printf "\e[1;37m") \
		LESS_TERMCAP_me=$(printf "\e[0m") \
		LESS_TERMCAP_se=$(printf "\e[0m") \
		LESS_TERMCAP_so=$(printf "\e[1;47;30m") \
		LESS_TERMCAP_ue=$(printf "\e[0m") \
		LESS_TERMCAP_us=$(printf "\e[0;36m") \
			man "$@"
}

To customize the colors, see Wikipedia:ANSI escape code for reference.

使用浏览器阅读手册页

Instead of the standard interface, using browsers such as lynx and Firefox to view man pages allows users to reap info pages' main benefit: hyperlinked text. Additionally, KDE users can read man pages in Konqueror using:

man:<name>

Using Local Man Pages

First, install Template:Package AUR from the AUR.

Now, convert a man page:

$ man free | man2html -compress -cgiurl man$section/$title.$section$subsection.html > ~/man/free.html

Another use for Template:Codeline is exporting to raw, printer-friendly text:

$ man free | man2html -bare > ~/free.txt

The GNU implementation of man in the Arch repositories also has the ability to do this on its own:

$ man -H free

This will read your BROWSER environment variable to determine the browser. You can override this by passing the binary to the -H option.

使用在线手册页

There are several online databases of man pages, many of them listed on Wikipedia:Man_page#Repositories_of_manual_pages, including: