7.1. 文档资源

在你能搞懂引发问题的原因之前,你需要从原理上明白程序及其所包含的子程序所扮演的角色。为此,最好的方法是参考程序的文档;但这些文档往往数量巨大且分散,因此你也需要知道如何找到这些文档。

7.1.1. 手册页面

文化 读那该死的文档去!(RTFM)

本标题缩写意思是“读那该死的文档!(Read the F**king Manual)”,当然,也可以翻译得文雅一些,“读那些好文档(Read the Fine Manual)”。这个短语经常是用来回复新手的提问时,表达略带厌烦的情绪。有人认为这种回应略显粗鲁,毕竟对于提问的人来说,他们未必会介意去阅读文档。但也有人认为,这种经典的回应方式聊胜于无(至少指出已有的文档包含了相关的信息),毕竟也比直接得到一个满是抱怨并且十分冗长答复要好些。

在任何情况下,如果有人用“RTFM”来回应你,通常并没有任何冒犯的意思。要是这种回应让你觉得脑火,要么你就直接无视,要么你最好在提问之初就说明在手册当中没有找到相关信息。在上论坛提问前,最好也能描述你已经寻找资料的一些步骤。Eric Raymod曾发表过一篇指引性的文章,就如何提问给出了建议,这能有效避免常识性的错误并得到有用的答案。文章地址是:

http://catb.org/~esr/faqs/smart-questions.html

Manual pages, while relatively terse in style, contain a great deal of essential information. We will quickly go over the command for viewing them, provided by the man-db package. Simply type man *manual-page* — the manual page usually goes by the same name as the command whose documentation is sought. For example, to learn about the possible options for the cp command, you would type the man cp command at the shell prompt (see sidebar 基本知识 命令行解析器 - Shell).

基本知识 命令行解析器 - Shell

命令行解析器,通常也称作“shell”, 是一种执行用户输入或者文本命令的程序。在交互模式下,会显示一个提示符(普通用户会显示一个$ 符号,管理员用户会显示一个#),用来表示shell已经就绪,可以读取一个新的命令。附录 B, 简短辅导课程 描述了shell的基本使用方法。

默认且经常会被用到的shell程序是 bash (Bourne Again SHell), 当然也有其他,包括 dashcshtcshzsh等等。

Among other things, most shells offer help (type help) and assistance during input at the prompt, such as the completion of command or file names (which you can generally activate by pressing the tab key), or recalling previous commands (history management; i.e. check out the mappings for “page up” and “page down” in /etc/inputrc).

Man pages not only document commands and programs accessible from the command line, but also configuration files, system calls, library functions, and so forth. Sometimes names can collide. For example, the shell’s read command has the same name as the read system call. This is why manual pages are organized in numbered sections:

1

可从命令行执行的程序

2

系统调度(由内核提供的函数)

3

库函数(有系统库提供的函数)

4

设备(在Unix下,设备就是一些特殊的文件,通常放置在 /dev/ 目录下);

5

配置文件(格式与约定)

6

游戏

7

系统宏与标准集

8

系统管理命令

9

内核例程。

如果出现上述的冲突情况,你可以在使用手册页面查看文档的时候指定对应的分类数字(section):例如浏览系统调用read的文档时,你可以键入man 2 read。如果不指定具体的分类数字(section),系统则会从小到大获取第一个数字作为默认值。因此直接输入man shadow的时候,系统就会返回 shadow(5)的文档内容,这是在分类页面1-4都没有shadow这个命令的手册页面所导致的。

TIP whatis命令

如果你只是想显示一些简短的描述来确认所输入的命令是否自己所需,不希望显示完整的手册页面的话,只需要输入whatis *command*就可以了。

  1. $

这部分描述同样包含在手册页面的NAME部分。

当然,如果你连命令的名字都不知道,手册页面恐怕就无能为力了。遇到这种情况,我们可以用命令 apropos 来解决,这个命令能帮你查询手册页面的功能,或者简要的描述。每个手册页面都有一个单行的描述。apropos 返回手册页面请求的关键字列表。关键字选择得恰当,就能通过此工具很快得到结果。

例 7.1. 通过apropos查找 cp命令

  1. $

提示通过以下链接浏览

很多的手册页面都有”SEE ALSO”的段落,通常位于内容的最后。其作用是同时指出其他相关的类似命令,或者外部的文档。这样就可以在不选择第一个选项的情况下,仍可寻找到相关文档。

The man command is not the only means of consulting the manual pages, since khelpcenter and konqueror (by KDE) and yelp (under GNOME) programs also offer this possibility. There is also a web interface, provided by the man2html package, which allows you to view manual pages in a web browser. On a computer where this package is installed, use this URL after following the instructions in /usr/share/doc/man2html/README.Debian:

http://localhost/cgi-bin/man/man2html

这个工具需要一个web服务器,因此你应该将其安装包安装在一台服务器上:本地网络的所有用户将会因此受惠(包括非linux的机器),也不需要在每台工作站上面都安装http服务。如果你的服务器同时也能从外部网络访问的话,比较建议对这项服务的访问限制在本地网络的用户。

Last but not least, you can view all manual pages available in Debian (even those that are not installed on your machine) on the manpages.debian.org service. It offers each manual page in multiple versions, one for each Debian release.

https://manpages.debian.org

DEBIAN政策对手册页面的规定

Debian要求每个程序都必须配备手册页面。如果上游的作者没有提供这份文档,Debian软件包的维护者就必须为读者编写一份最少内容的页面作为原文档。

7.1.2. info文档

GNU项目为其大部分的程序编写了info格式的文档;这将解释为何很多手册页面的内容直接引用 info 文档的内容。这种格式有一定的优势,但默认的查看程序(也就是info 命令)却会使得查看文档变得复杂。更好的建议,是使用 pinfo 程序来替代默认的程序(使用 pinfo 的软件包)。

info文档拥有一个分层次的结构,如果在调用 pinfo 命令的时候没有输入任何参数,它将会列出第一层所有有效的节点。通常来说,节点名称与命令的名称相对应。

With pinfo navigating between these nodes is easy to achieve with the arrow keys. Alternatively, you could also use a graphical browser, which is a lot more user-friendly. Again, konqueror and yelp work; the info2www package also provides a web interface.

http://localhost/cgi-bin/info2www

需要注意的是,info 系统不支持翻译功能,这点与 man 系统不一样。因此 info 总是以英文编写。然而,当你尝试用 pinfo 命令访问一个并不存在的info页面的时候,将会回退到同名的 man 页面(如果该页面存在),这时的页面有可能是被翻译了的。

7.1.3. 特定的文档

每个软件包都包含起自身的文档。即使是最缺乏文档的包也至少会包含 README 文件,里面包含了有趣并且(或者)重要的信息。这些文档通常会被安装在/usr/share/doc/*package*/ 目录(这里的 package 代表软件包的名字)。当文件特别巨大的情况下,这些文档不会包含在程序的主包当众,而是另外提供一个通常以 *package*-doc 的包名格式另外提供一个软件包。通过主包名称通常都能很快找到文档包。

The /usr/share/doc/*package*/ directory also contains some files provided by Debian which complete the documentation by specifying the package’s particularities or improvements compared to a traditional installation of the software. The README.Debian file also indicates all of the adaptations that were made to comply with the Debian Policy. The changelog.Debian.gz file allows the user to follow the modifications made to the package over time: it is very useful to try to understand what has changed between two installed versions that do not have the same behavior. Finally, there is sometimes a NEWS.Debian.gz file which documents the major changes in the program that may directly concern the administrator (see 第 6.7.2 节 “处理升级后的问题”).

7.1.4. 网站

在大部分情况下,自由软件(Free software)都拥有各自的网站,网站上面提供程序发布的地址,以及提供了开发者和用户交流的社区。这些网站通常都有以不同形式组织起来的如下一些信息:官方文档, FAQ(常见问题列表), 邮件列表和归档内容等等。通常,你所遇到的问题都已经被很多人提出过了的,这你就能在FAQ和邮件列表归档等方式找到解决的方法。同归对搜索引擎指定搜索的域名和子域名,能切实有效的提高查找问题的效率。但凡搜索引擎所返回的页面过多或者结果并非你所想要,你可以通过添加查询关键字 debian 来限制结果和目标的相关信息。

TIP From error to solution

如果软件返回了一个特定的错误信息,你可以将这段信息以半角双引号"括起(这样能保证以完整的句子进行查找,而不是单个单词),输入到搜索引擎中进行查找。在大部分情况下,第一条链接就会包括你所需要的答案。

在其它情况下,会出现一种经常遇到的错误信息,例如 “Permission denied”。在这种情况下,你最好检查一下相关元素的权限情况如何(文件、用户ID,组别等)。

If you do not know the address for the software’s website, there are various means of getting it. First, check if there is a Homepage field in the package’s meta-information (apt show *package*). Alternately, the package description may contain a link to the program’s official website. If no URL is indicated, look at /usr/share/doc/*package*/copyright. The Debian maintainer generally indicates in this file where they got the program’s source code, and this is likely to be the website that you need to find. If at this stage your search is still unfruitful, consult a free software directory, such as FSF’s Free Software Directory, or search directly with a search engine, such as Google, DuckDuckGo, Yahoo, etc.

https://directory.fsf.org/wiki/Main_Page

You might also want to check the Debian wiki, a collaborative website where anybody, even simple visitors, can make suggestions directly from their browsers. It is used equally by developers who design and specify their projects, and by users who share their knowledge by writing documents collaboratively.

https://wiki.debian.org/

7.1.5. 入门指导类文档(HOWTO文档)

A HOWTO is a document that describes, in concrete terms and step by step, “how to” reach a predefined goal. The covered goals are relatively varied, but often technical in nature: for example, setting up IP Masquerading, configuring software RAID, installing a Samba server, etc. These documents often attempt to cover all of the potential problems likely to occur during the implementation of a given technology.

Many such tutorials are managed by the Linux Documentation Project (LDP), whose website hosts all of these documents:

https://www.tldp.org/

Debian also provides tutorials for its users:

https://www.debian.org/doc/

All these documents should be taken with a grain of salt. They are often several years old; the information they contain is sometimes obsolete. This phenomenon is even more frequent for their translations, since updates are neither systematic nor instant after the publication of a new version of the original documents. Further many tutorials nowadays are provided by bloggers, sharing their individual solution with the interested reader. They often lack important information, i.e. the reason why some configuration has been chosen over another, or why some option has been enabled or disabled. Because blogging and creating own websites made it so easy to share, many of these often short tutorials exist, but only a few are actively maintained and well-kept. This can make it hard, to find the “right” one for you. This is all part of the joys of working in a volunteer environment and without constraints…