mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-02-03 23:40:14 +08:00
Merge pull request #22200 from wxy/20210611-RTFM--How-to-Read-(and-Understand)-the-Fantastic-Man-Pages-in-Linux
TSL&PRF:sources/tech/20210611 RTFM- How to Read (and Understand) the Fantastic Man Pages in Linux.md
This commit is contained in:
commit
8179d4ace3
@ -1,353 +0,0 @@
|
||||
[#]: subject: (RTFM! How to Read (and Understand) the Fantastic Man Pages in Linux)
|
||||
[#]: via: (https://itsfoss.com/linux-man-page-guide/)
|
||||
[#]: author: (Bill Dyer https://itsfoss.com/author/bill/)
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (wxy)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
|
||||
RTFM! How to Read (and Understand) the Fantastic Man Pages in Linux
|
||||
======
|
||||
|
||||
The _man pages_, short for _reference manual pages_, are your keys to Linux. Everything you want to know is there – take it all in an run with it. The collection of documents will never win a Pulitzer prize, but the set is quite accurate and complete. The man pages are _the_ primary source and that authority is well-known.
|
||||
|
||||
While they are the “go to” source, they aren’t the most pleasant to read. Once, in a long past philosophy class, I was told that reading [Aristotle][1] was the most boring read around. I disagreed: when it comes to dry reading, Aristotle comes in at a distant second to man pages.
|
||||
|
||||
At first glance, the pages may look incomplete but, believe it or not, the man pages aren’t designed to hide information from you – it’s just that there is so much information that the pages have to be structured and information is given in the most brief form possible. The explanations are rather spartan and they will take some getting used to, but once you get the hang of using them, you’ll see how useful they actually are.
|
||||
|
||||
### Getting Started with the man Pages in Linux
|
||||
|
||||
The pages are viewed through a utility called, `man`, and the command to use it is rather easy. In the simplest form, to use `man`, you type `man` on the command line, followed by a `space` and the command that you want to look up, such as `ls` or `cp`, like so:
|
||||
|
||||
```
|
||||
man ls
|
||||
```
|
||||
|
||||
man opens the manual page of the `ls` command.
|
||||
|
||||
![][2]
|
||||
|
||||
You can move up and down with the arrow keys and press `q` to quit viewing the man page. Usually, the man pages are opened with less so the keyboard shortcuts for less command work in man as well.
|
||||
|
||||
For example, you can search for a specific text using /search_term and so on.
|
||||
|
||||
There is an introduction to the man pages and it’s important that you read this one. It spells out, in great detail, how the man pages are laid out and organized.
|
||||
|
||||
To see this page, open a terminal and type:
|
||||
|
||||
```
|
||||
man man
|
||||
```
|
||||
|
||||
![man page of man][3]
|
||||
|
||||
### Section What?
|
||||
|
||||
Before you begin to look at man pages much deeper, it will be helpful to know that man pages have a set page layout _and_ a filing scheme. This can be confusing to a newcomer since I can say: “Look at the NAME _section_ of the man page for `ls`.” I can also say, “Look at the man page for `passwd` in _section_ 5.”
|
||||
|
||||
I italicized the word, _section_ to try to show a source of confusion. The word, _section_ is being used in two different ways, but the difference isn’t always explained to newcomers.
|
||||
|
||||
I am not sure why this confusion sets in, but I have seen it happen a few times back when I trained new users and entry-level sysadmins. I think it might be tunnel vision. Focusing on one thing can make a person forget about another. It’s a lot like not being able to see the forest because the trees are in the way.
|
||||
|
||||
To those who know the difference already, you can skip this sub-section. This part is directed to the people new to man pages.
|
||||
|
||||
Here is the difference:
|
||||
|
||||
#### The man page
|
||||
|
||||
Individual man pages are made to show blocks of information. For example, every man page has a **NAME** section to show the name of the command along with a brief description. There will be another block of information, called **SYNOPSIS** to show how the command is used, and so on.
|
||||
|
||||
![][4]
|
||||
|
||||
Every man page will have these, and other headings. These sections, or headings, on individual man pages, helps keep things consistent and information compartmentalized.
|
||||
|
||||
#### The Manual
|
||||
|
||||
The use of _section_, as in “Look at the man page for `passwd` in _section_ 5” speaks of the manual as a whole. When we look at only one page, it can be easy to overlook that, but the man page for `passwd` is part of the same manual that has a man page for `ls`, `rm`, `date`, `cal`, and others.
|
||||
|
||||
The entire Linux manual is huge; it has thousands of pages. Some of those pages have specialized information. Some pages have information that programmers need, while others have information unique to networking, and others that system administrators would be interested in.
|
||||
|
||||
These pages are grouped according to their unique purpose. Think of splitting the entire manual into several chapters – each chapter having a specific topic. There are 9 or so chapters (very large ones at that). It just so happens that these chapters are called _sections_.
|
||||
|
||||
To sum this up:
|
||||
|
||||
* Sections of a single page of the manual (what we call the man page) are blocks of information defined by the headings and
|
||||
* Sections of the manual-at-large (the collection of all of the pages) are chapters which happen to be called _sections_.
|
||||
|
||||
|
||||
|
||||
Now you know the difference and, hopefully, the rest of this article will be easier to follow.
|
||||
|
||||
### man Page Sections
|
||||
|
||||
You will be looking at different man pages so let’s study the individual page layout first.
|
||||
|
||||
Manual pages are split into several headings and they may vary from vendor to vendor, but they will be similar. The general breakdown is as follows:
|
||||
|
||||
* NAME
|
||||
* SYNOPSIS
|
||||
* DESCRIPTION
|
||||
* EXAMPLES
|
||||
* DIAGNOSTICS
|
||||
* FILES
|
||||
* LIMITS
|
||||
* PORTABILITY
|
||||
* SEE ALSO
|
||||
* HISTORY WARNING (or Bugs)
|
||||
* NOTES
|
||||
|
||||
|
||||
|
||||
**NAME** – Under this heading is the command name and a brief description of the command.
|
||||
|
||||
**SYNOPSIS** – Shows how the command is used. For instance, here is a synopsis of the `cal` command:
|
||||
|
||||
```
|
||||
cal [Month] [Year]
|
||||
```
|
||||
|
||||
The synopsis begins with the name of the command, with a list of options following. The synopsis takes the general form of a command line; it shows what you can type and the order of the arguments. Arguments in square brackets (`[]`) are optional; you can leave these arguments out and the command will still work correctly. Items not in brackets must be used.
|
||||
|
||||
Take note that brackets are for readability only. They should not be typed when you enter a command.
|
||||
|
||||
**DESCRIPTION** – Describes the command or utility as to what it does and how you can use it. This section usually starts off with an explanation of the synopsis as well as telling what happens if you omit any of the optional arguments. This section may be subdivided for long or complex commands.
|
||||
|
||||
**EXAMPLES** – Some man pages provide examples of how the command or utility can be used. If this section is present, the page tries to give a few simple usage examples, as well as more complex examples to show how complex tasks can be completed.
|
||||
|
||||
**DIAGNOSTICS** – This section lists status or error messages returned by the command or utility. Self-explanatory error and status messages aren’t usually shown. Messages that may be hard to understand are usually listed.
|
||||
|
||||
**FILES** This section contains a list of supplementary files used by UNIX to run this specific command. Here, _supplementary_ files are files not specified on the command line. For example, if you were looking at a man page for the `passwd` command, you may find `/etc/passwd` listed in this section since that is where UNIX stores password information.
|
||||
|
||||
**LIMITS** – This section describes any limitations of a utility. Operating system and hardware limitations are usually not listed as they are outside of the utility’s control.
|
||||
|
||||
**PORTABILITY** – Lists other systems where the utility is available, along with how other versions of the utility may differ.
|
||||
|
||||
**SEE ALSO** – lists related man pages that contain relevant information.
|
||||
|
||||
**HISTORY** – Gives a brief history of the command such as when it first appeared.
|
||||
|
||||
**WARNING** – If this section is present, it contains important advice for users.
|
||||
|
||||
**NOTES** – Not as severe as a warning, but important information.
|
||||
|
||||
Again, not all man pages use the exact headings listed above, but they’re close enough to follow.
|
||||
|
||||
### The Manual’s Sections
|
||||
|
||||
The entire Linux manual collection of pages are traditionally divided into numbered sections:
|
||||
|
||||
* **Section 1** : Shell commands and applications
|
||||
* **Section 2** : Basic kernel services – system calls and error codes
|
||||
* **Section 3** : Library information for programmers
|
||||
* **Section 4** : Network services – if TCP/IP or NFS is installed Device drivers and network protocols
|
||||
* **Section 5** : Standard file formats – for example: shows what a _tar_ archive looks like.
|
||||
* **Section 6** : Games
|
||||
* **Section 7** : Miscellaneous files and documents
|
||||
* **Section 8** : System administration and maintenance commands
|
||||
* **Section 9** : Obscure kernel specs and interfaces
|
||||
|
||||
|
||||
|
||||
The grouping of pages into these groups makes for more efficient searching. I sometimes do a little programming where I work, so I spend a little time look at section 3 man pages. I also do a little work in networking, so I’ve been known to wade through the networking section, and as a system administrator of several experimental machines, I spend a good deal of time in section 8.
|
||||
|
||||
Grouping pages into specific (chapters) sections make searching for information easier – both for the human needing it, and for the machine doing the searching.
|
||||
|
||||
You can tell which page belongs to which section by the number next to the name. For example, if you’re looking at a man page for `ls` and the very top of the page says this: `LS(1)`, you are viewing the `ls` page in section 1, which contains the pages about shell commands and applications.
|
||||
|
||||
Here is another example. If you’re looking at a man page for `passwd` and the top of the page shows: `PASSWD(1)`, you are reading the page from section 1 that describes how the `passwd` command changes passwords for user accounts. If you see `PASSWD(5)`, you are reading about the the password file and how it is made up.
|
||||
|
||||
![][5]
|
||||
|
||||
`passwd` happens to be be two different things: it is the name of a command and a name of a file. Again, section 1 describes the command, while section 5 covers file formats.
|
||||
|
||||
The number in the parenthesis is the big clue – that number tells you what section that the page you’re reading, came from.
|
||||
|
||||
### Searching for a Specific Section
|
||||
|
||||
The basic command:
|
||||
|
||||
```
|
||||
man name
|
||||
```
|
||||
|
||||
will search for the man page identified by _name_ in every section, displaying them one at a time, in numerical order. To limit your search to a specific section, use an argument with the `man` command, like so:
|
||||
|
||||
```
|
||||
man 1 name
|
||||
```
|
||||
|
||||
This command will only search section 1, of the man pages, for _name_. Using our `passwd` example earlier, this means that we can keep the search targeted. If I want to read about the `passwd` command, I can type this in the terminal:
|
||||
|
||||
```
|
||||
man 1 passwd
|
||||
```
|
||||
|
||||
The `man` utility will only search through section 1 for `passwd` and display it. It will not look through any other section for `passwd`.
|
||||
|
||||
An alternative method for this command is to type: `man passwd.1`
|
||||
|
||||
### Using man -k to Search all man Pages Containing a Certain Keyword
|
||||
|
||||
The _man_ command, with the _k_ option (often called a _flag_ or _switch_) can come in handy if you want a listing of man pages containing a certain keyword. For example, if you want to see a list of man pages that deal with, say, `ftp`, you can get this list by typing:
|
||||
|
||||
```
|
||||
man -k ftp
|
||||
```
|
||||
|
||||
From the listing that will follow, you’ll be able to pick a specific man page to read:
|
||||
|
||||
![man k example][6]
|
||||
|
||||
On some systems, before `man -k` will work, the system administrator will need to run a utility called `catman`.
|
||||
|
||||
### Using whatis and whereis Commands to Know the Manual’s Sections
|
||||
|
||||
There are two nifty utilities that can be helpful in your search for information: whatis and whereis.
|
||||
|
||||
#### whatis
|
||||
|
||||
There are times when we can quite get the information we need. Chances are great that the information we need is available – finding it can be a small problem.
|
||||
|
||||
For example, if I want to look at the man page about the `passwd` file, and I type this on the terminal:
|
||||
|
||||
```
|
||||
man passwd
|
||||
```
|
||||
|
||||
I would see the page that tells me all about the `passwd` command, but nothing about the `passwd` file. I know that `passwd` is a command and there’s also a `passwd` file, but sometimes, I might forget that. It’s then that I realize that file structures are in a different section in the man pages, so I type:
|
||||
|
||||
```
|
||||
man 4 passwd
|
||||
```
|
||||
|
||||
and I get this reply:
|
||||
|
||||
```
|
||||
No manual entry for passwd in section 4
|
||||
See 'man 7 undocumented' for help when manual pages are not available.
|
||||
```
|
||||
|
||||
Another lapse of forgetfulness. File structures are in section 4 of System V UNIX pages. Years ago, when I built files, I used `man 4...` _a lot_; it’s still a habit with me. So where is it in the Linux manual?
|
||||
|
||||
It’s time to call `whatis` to straighten me out. To do this, I type this in my terminal:
|
||||
|
||||
```
|
||||
whatis passwd
|
||||
```
|
||||
|
||||
and I see the following:
|
||||
|
||||
```
|
||||
passwd (1) - change user password
|
||||
passwd (1ssl) - compute password hashes
|
||||
passwd (5) - the password file
|
||||
```
|
||||
|
||||
Ah! the page for the `passwd` file is in section 5. Now I am set straight and can access the information I want:
|
||||
|
||||
```
|
||||
man 5 passwd
|
||||
```
|
||||
|
||||
and I am brought to the man page that has the information I need.
|
||||
|
||||
`whatis` is handy utility that can tell you, in a brief one-liner, what a command does. Imagine that you want to know what `cal` does without having to view the man page. Just type this at the command prompt:
|
||||
|
||||
```
|
||||
whatis cal
|
||||
```
|
||||
|
||||
and you will see this in response:
|
||||
|
||||
```
|
||||
cal (1) - displays a calendar and the date of Easter
|
||||
```
|
||||
|
||||
Now that you know about the `whatis` command, I can let you in on a secret – there is a `man` command equivalent. To get this, we use the `-f` switch: `man -f ...`
|
||||
|
||||
Try it out. Type: `whatis cal` at a terminal prompt. Once that executes, type: `man -f cal`. The output of both commands will be identical.
|
||||
|
||||
![whatis cal and man f cal outputs are the same][7]
|
||||
|
||||
#### whereis
|
||||
|
||||
The very name of the `whereis` command explains itself – it tells you where a program is within the filesystem. It will also tell you where the man page is stored too. Using `cal` as an example again, I type this at the prompt:
|
||||
|
||||
```
|
||||
whereis cal
|
||||
```
|
||||
|
||||
I will see this:
|
||||
|
||||
![whereis cal output][8]
|
||||
|
||||
Look carefully at the reply. The answer is on one line, but it tells me two things:
|
||||
|
||||
`/usr/bin/cal` is where the `cal` program is and
|
||||
|
||||
`/usr/share/man/man1/cal.1.gz` is where the man page resides (I’m also clued into the fact that the man page is compressed, but not to worry – the man command knows how to decompress it on the fly)
|
||||
|
||||
`whereis` is PATH dependent; it can only tell you where files are if they are in your PATH environment.
|
||||
|
||||
You may be wondering if there is an equivalent `man` command for `whereis`. There isn’t one that will tell you where the executable file is, but there is a switch you can use that will tell you where the man page is. Using the `date` command in this example, if we type:
|
||||
|
||||
```
|
||||
whereis date
|
||||
```
|
||||
|
||||
at a terminal prompt, we will see:
|
||||
|
||||
![whereis date output][9]
|
||||
|
||||
We see that the `date` program is in the `/usr/bin/` directory and the name and location of its man page is: `/usr/share/man/man1/date.1.gz`
|
||||
|
||||
The closest we can get man to act like `whereis` is to use the `-w` switch. We won’t get the location of the program, but we can at least get the location of the man page, like this:
|
||||
|
||||
```
|
||||
man -w date
|
||||
```
|
||||
|
||||
and we will see this returned:
|
||||
|
||||
![][10]
|
||||
|
||||
You know about `whatis` and `whereis` as well as a method to get the `man` command to do the same (or close) thing. I showed both ways for a couple of different reasons.
|
||||
|
||||
For years, I used `whatis` and `whereis` since they were in my training manuals. I didn’t learn about `man -f ...` and `man -w ...` until fairly recently. I’m sure I looked at the man page for `man` hundreds of times, but I never noticed the `-f` and `-w` switches. I was always looking at the man page for something else (i.e. `man -k ...`). I concentrated only on what I needed to find and ignored the rest. Once I found the information I needed, I would leave the page and get the work done, not paying attention to some of the other gems the command had to offer.
|
||||
|
||||
This is okay since this is partly what the man pages are for: to help you get work done.
|
||||
|
||||
It wasn’t until I was recently showing someone how to use man pages, that I took the time to just read – “to see what else was possible” – and we took real notice of the information about what the `man` command’s `-f` and `-w` flags can do.
|
||||
|
||||
No matter how long you have been using Linux, or how experienced, there is always something new to learn.
|
||||
|
||||
The man pages will tell you what you may need to know to work through a certain task – but they also hold a lot more – enough to make you look like a magician – but only if you take the time to read.
|
||||
|
||||
### Conclusion
|
||||
|
||||
If you spend some time and effort with the man pages, you will come out on top. Your proficiency of the man pages, will play a huge part in your mastery over Linux.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://itsfoss.com/linux-man-page-guide/
|
||||
|
||||
作者:[Bill Dyer][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://itsfoss.com/author/bill/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://www.britannica.com/biography/Aristotle
|
||||
[2]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2021/06/man-page-example-800x527.png?resize=800%2C527&ssl=1
|
||||
[3]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/05/man_man.png?resize=800%2C455&ssl=1
|
||||
[4]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2021/06/man-page-example-1.png?resize=800%2C527&ssl=1
|
||||
[5]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2021/06/man-page-passwd-command.png?resize=1026%2C676&ssl=1
|
||||
[6]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/05/man-k_example.png?resize=800%2C200&ssl=1
|
||||
[7]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2021/05/whatis_cal_man-f_cal.png?resize=800%2C135&ssl=1
|
||||
[8]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/05/whereis_cal.png?resize=800%2C100&ssl=1
|
||||
[9]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/05/whereis_date.png?resize=800%2C100&ssl=1
|
||||
[10]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2021/05/man-w_date-1.png?resize=800%2C100&ssl=1
|
@ -0,0 +1,347 @@
|
||||
[#]: subject: (RTFM! How to Read \(and Understand\) the Fantastic Man Pages in Linux)
|
||||
[#]: via: (https://itsfoss.com/linux-man-page-guide/)
|
||||
[#]: author: (Bill Dyer https://itsfoss.com/author/bill/)
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (wxy)
|
||||
[#]: reviewer: (wxy)
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
|
||||
RTFM!如何阅读(和理解)Linux 中神奇的手册页
|
||||
======
|
||||
|
||||
<ruby>手册页<rt>man pages</rt></ruby>,即<ruby>参考手册页<rt>reference manual pages</rt></ruby>的简称,是你进入 Linux 的钥匙。你想知道的一切都在那里,包罗万象。这套文档永远不会赢得普利策奖,但这套文档是相当准确和完整的。手册页是主要信源,其权威性是众所周知的。
|
||||
|
||||
虽然它们是源头,但阅读起来并不是最令人愉快的。有一次,在很久以前的哲学课上,有人告诉我,阅读 [亚里士多德][1] 是最无聊的阅读。我不同意:说到枯燥的阅读,亚里士多德远远地排在第二位,仅次于手册页。
|
||||
|
||||
乍一看,这些页面可能看起来并不完整,但是,不管你信不信,手册页并不是为了隐藏信息 —— 只是因为信息量太大,这些页面必须要有结构,而且信息是以尽可能简短的形式给出的。这些解释相当简略,需要一些时间来适应,但一旦你掌握了使用它们的技巧,你就会发现它们实际上是多么有用。
|
||||
|
||||
### Linux 中的手册页入门
|
||||
|
||||
这些页面是通过一个叫做 `man` 的工具查看的,使用它的命令相当简单。在最简单的情况下,要使用 `man`,你要在命令行上输入 `man`,后面加一个空格和你想查询的命令,比如 `ls` 或 `cp`,像这样:
|
||||
|
||||
```
|
||||
man ls
|
||||
```
|
||||
|
||||
`man` 会打开 `ls` 命令的手册页。
|
||||
|
||||
![][2]
|
||||
|
||||
你可以用方向键上下移动,按 `q` 退出查看手册页。通常情况下,手册页是用 `less` 打开的,所以 `less` 命令的键盘快捷键在 `man` 中也可以使用。
|
||||
|
||||
例如,你可以用 `/search_term` 来搜索一个特定的文本,等等。
|
||||
|
||||
有一个关于手册页的介绍,这是一篇值得阅读介绍。它非常详细地说明了手册页是如何布局和组织的。
|
||||
|
||||
要看这个页面,请打开一个终端,然后输入:
|
||||
|
||||
```
|
||||
man man
|
||||
```
|
||||
|
||||
![man page of man][3]
|
||||
|
||||
### 节
|
||||
|
||||
在你开始更深入地研究手册页之前,知道手册页有一个固定的页面布局和一个归档方案会有帮助。这可能会让新手感到困惑,因为我可以说:“看手册页中关于 `ls` 的 NAME <ruby>节<rt>section</rt></ruby>”,我也可以说:“看第 5 <ruby>节<rt>section</rt></ruby>中的 `passwd` 的手册页。”
|
||||
|
||||
我把 “<ruby>节<rt>section</rt></ruby>” 这个词用斜体字表示,是为了显示混淆的来源。这个词,“节” 被用于两种不同的方式,但并不总是向新人解释其中的区别。
|
||||
|
||||
我不确定为什么会出现这种混淆,但我在培训新用户和初级系统管理员时看到过几次这种混淆。我认为这可能是隧道视野,专注于一件事会使一个人忘记另一件事。一叶障目,不见泰山。
|
||||
|
||||
对于那些已经知道其中的区别的人,你可以跳过这一小节。这一部分是针对那些刚接触到手册页的人。
|
||||
|
||||
这就是区别:
|
||||
|
||||
#### 对于手册页
|
||||
|
||||
单独的手册页是用来显示信息块的。例如,每个手册页都有一个“NAME”节,显示命令的名称和简短的描述。还会有另一个信息块,称为“SYNOPSIS”,显示该命令是如何使用的,以此类推。
|
||||
|
||||
![][4]
|
||||
|
||||
每个手册页都会有这些,以及其他的标题。这些在各个手册页上的节,或者说标题,有助于保持事情的一致性和信息的分工。
|
||||
|
||||
#### 对于手册
|
||||
|
||||
使用“节”,如 “查看第 5 节中的 `passwd` 的手册页”,是指整个手册的内容。当我们只看一页时,很容易忽略这一点,但是 `passwd` 手册页是同一本手册的一部分,该手册还有 `ls`、`rm`、`date`、`cal` 等的手册页。
|
||||
|
||||
整个 Linux 手册是巨大的;它有成千上万的手册页。其中一些手册页有专门的信息。有些手册页有程序员需要的信息,有些手册页有网络方面的独特信息,还有一些是系统管理员会感兴趣的。
|
||||
|
||||
这些手册页根据其独特的目的被分组。想想看,把整个手册分成几个章节 —— 每章有一个特定的主题。有 9 个左右的章节(非常大的章节)。碰巧的是,这些章节被称为“节”。
|
||||
|
||||
总结一下:
|
||||
|
||||
* 手册中单页(我们称之为“手册页”)的节是由标题定义的信息块。
|
||||
* 这个大的手册(所有页面的集合)中的章节,刚好被称为“节”。
|
||||
|
||||
现在你知道区别了,希望本文的其余部分会更容易理解。
|
||||
|
||||
### 手册页的节
|
||||
|
||||
你将会看到不同的手册页,所以让我们先研究一下各个页面的布局。
|
||||
|
||||
手册页被分成几个标题,它们可能因提供者不同而不同,但会有相似之处。一般的分类如下:
|
||||
|
||||
* `NAME`(名称)
|
||||
* `SYNOPSIS`(概要)
|
||||
* `DESCRIPTION`(描述)
|
||||
* `EXAMPLES`(例子)
|
||||
* `DIAGNOSTICS`(诊断)
|
||||
* `FILES`(文件)
|
||||
* `LIMITS`(限制)
|
||||
* `PORTABILITY`(可移植性)
|
||||
* `SEE ALSO`(另见)
|
||||
* `HISTORY`(历史)
|
||||
* WARNING`(警告)或 `BUGS`(错误)
|
||||
* `NOTES`(注意事项)
|
||||
|
||||
`NAME` - 在这个标题下是命令的名称和命令的简要描述。
|
||||
|
||||
`SYNOPSIS` - 显示该命令的使用方法。例如,这里是 `cal` 命令的概要:
|
||||
|
||||
```
|
||||
cal [Month] [Year]
|
||||
```
|
||||
|
||||
概要以命令的名称开始,后面是选项列表。概要采用命令行的一般形式;它显示了你可以输入的内容和参数的顺序。方括号中的参数(`[]`)是可选的;你可以不输入这些参数,命令仍然可以正常工作。不在括号内的项目必须使用。
|
||||
|
||||
请注意,方括号只是为了便于阅读。当你输入命令时,不应该输入它们。
|
||||
|
||||
`DESCRIPTION` - 描述该命令或工具的作用以及如何使用它。这一节通常以对概要的解释开始,并说明如果你省略任何一个可选参数会发生什么。对于长的或复杂的命令,这一节可能会被细分。
|
||||
|
||||
`EXAMPLES ` - 一些手册页提供了如何使用命令或工具的例子。如果有这一节,手册页会尝试给出一些简单的使用例子,以及更复杂的例子来说明如何完成复杂的任务。
|
||||
|
||||
`DIAGNOSTICS` - 本节列出了由命令或工具返回的状态或错误信息。通常不显示不言自明的错误和状态信息。通常会列出可能难以理解的信息。
|
||||
|
||||
`FILES` - 本节包含了 UNIX 用来运行这个特定命令的补充文件的列表。这里,“补充文件”是指没有在命令行中指定的文件。例如,如果你在看 `passwd` 命令的手册,你可能会发现 `/etc/passwd` 列在这一节中,因为 UNIX 是在这里存储密码信息。
|
||||
|
||||
`LIMITS` - 本节描述了一个工具的限制。操作系统和硬件的限制通常不会被列出,因为它们不在工具的控制范围内。
|
||||
|
||||
`PORTABILITY` - 列出其他可以使用该工具的系统,以及该工具的其他版本可能有什么不同。
|
||||
|
||||
`SEE ALSO` - 列出包含相关信息的相关手册页。
|
||||
|
||||
`HISTORY` - 提供命令的简要历史,如它第一次出现的时间。
|
||||
|
||||
`WARNING` - 如果有这个部分,它包含了对用户的重要建议。
|
||||
|
||||
`NOTES` - 不像警告那样严重,但也是重要的信息。
|
||||
|
||||
同样,并不是所有的手册都使用上面列出的确切标题,但它们足够接近,可以遵循。
|
||||
|
||||
### 手册的节
|
||||
|
||||
整个 Linux 手册集合的手册页传统上被划分为有编号的节:
|
||||
|
||||
**第 1 节**:Shell 命令和应用程序
|
||||
**第 2 节**:基本内核服务 - 系统调用和错误代码
|
||||
**第 3 节**:为程序员提供的库信息
|
||||
**第 4 节**:网络服务 - 如果安装了 TCP/IP 或 NFS 设备驱动和网络协议
|
||||
**第 5 节**:文件格式 - 例如:显示 `tar` 存档的样子
|
||||
**第 6 节**:游戏
|
||||
**第 7 节**:杂项文件和文档
|
||||
**第 8 节**:系统管理和维护命令
|
||||
**第 9 节**:不知名的内核规格和接口
|
||||
|
||||
将手册页分成这些组,可以使搜索更有效率。在我工作的地方,我有时会做一些编程工作,所以我花了一点时间看第 3 节的手册页。我也做一些网络方面的工作,所以我也知道要涉足网络部分。作为几个实验性机器的系统管理员,我在第 8 节花了很多时间。
|
||||
|
||||
将手册网归入特定的节(章节),使搜索信息更加容易 —— 无论是对需要搜索的人,还是对进行搜索的机器。
|
||||
|
||||
你可以通过名称旁边的数字来判断哪个手册页属于哪个部分。例如,如果你正在看 `ls` 的手册页,而页面的最上面写着。 `LS(1)`,那么你正在浏览第 1 节中的 `ls` 页面,该节包含关于 shell 命令和应用程序的页面。
|
||||
|
||||
下面是另一个例子。如果你在看 `passwd` 的手册页,页面的顶部显示: `PASSWD(1)`,说明你正在阅读第 1 节中描述 `passwd` 命令如何更改用户账户密码的手册页。如果你看到 `PASSWD(5)`,那么你正在阅读关于密码文件和它是如何组成的的手册页。
|
||||
|
||||
![][5]
|
||||
|
||||
`passwd` 恰好是两个不同的东西:一个是命令的名称,一个是文件的名称。同样,第 1 节描述了命令,而第 5 节涉及文件格式。
|
||||
|
||||
括号中的数字是重要的线索 —— 这个数字告诉你正在阅读的页面来自哪一节。
|
||||
|
||||
### 搜索一个特定的节
|
||||
|
||||
基本命令:
|
||||
|
||||
```
|
||||
man -a name
|
||||
```
|
||||
|
||||
将在每一节中搜索由 `name` 标识的手册页,按数字顺序逐一显示。要把搜索限制在一个特定的部分,请在 `man` 命令中使用一个参数,像这样:
|
||||
|
||||
```
|
||||
man 1 name
|
||||
```
|
||||
|
||||
这个命令将只在手册页的第 1 节中搜索 `name`。使用我们前面的 `passwd` 例子,这意味着我们可以保持搜索的针对性。如果我想阅读 `passwd` 命令的手册页,我可以在终端输入以下内容:
|
||||
|
||||
```
|
||||
man 1 passwd
|
||||
```
|
||||
|
||||
`man` 工具将只在第 1 节中搜索 `passwd` 并显示它。它不会在任何其他节中寻找 `passwd`。
|
||||
|
||||
这个命令的另一种方法是输入: `man passwd.1`。
|
||||
|
||||
### 使用 man -k 来搜索包含某个关键词的所有手册页
|
||||
|
||||
如果你想获得包含某个关键词的手册页的列表,`man` 命令中的 `-k` 选项(通常称为标志或开关)可以派上用场。例如,如果你想看一个关于 `ftp` 的手册列表,你可以通过输入以下内容得到这个列表:
|
||||
|
||||
```
|
||||
man -k ftp
|
||||
```
|
||||
|
||||
在接下来的列表中,你可以选择一个特定的手册页来阅读:
|
||||
|
||||
![man k example][6]
|
||||
|
||||
在某些系统上,在 `man -k` 工作之前,系统管理员需要运行一个叫做 `catman` 的工具。
|
||||
|
||||
### 使用 whatis 和 whereis 命令来了解手册的各个节
|
||||
|
||||
有两个有趣的工具可以帮助你搜索信息:`whatis`和 `whereis`。
|
||||
|
||||
#### whatis
|
||||
|
||||
有的时候,我们完全可以得到我们需要的信息。我们需要的信息有很大的机会是可以找到的 —— 找到它可能是一个小问题。
|
||||
|
||||
例如,如果我想看关于 `passwd` 文件的手册页,我在终端上输入:
|
||||
|
||||
```
|
||||
man passwd
|
||||
```
|
||||
|
||||
我就会看到关于 `passwd` 命令所有信息的手册页,但没有关于 `passwd` 文件的内容。我知道 `passwd` 是一个命令,也有一个 `passwd` 文件,但有时,我可能会忘记这一点。这时我才意识到,文件结构在手册页中的不同节,所以我输入了:
|
||||
|
||||
```
|
||||
man 4 passwd
|
||||
```
|
||||
|
||||
我得到这样的答复:
|
||||
|
||||
```
|
||||
No manual entry for passwd in section 4
|
||||
See 'man 7 undocumented' for help when manual pages are not available.
|
||||
```
|
||||
|
||||
又是一次健忘的失误。文件结构在 System V UNIX 页面的第 4 节中。几年前,当我建立文件时,我经常使用 `man 4 ...`;这仍然是我的一个习惯。那么它在 Linux 手册中的什么地方呢?
|
||||
|
||||
现在是时候调用 `whatis` 来纠正我了。为了做到这一点,我在我的终端中输入以下内容:
|
||||
|
||||
```
|
||||
whatis passwd
|
||||
```
|
||||
|
||||
然后我看到以下内容:
|
||||
|
||||
```
|
||||
passwd (1) - change user password
|
||||
passwd (1ssl) - compute password hashes
|
||||
passwd (5) - the password file
|
||||
```
|
||||
|
||||
啊!`passwd` 文件的页面在第 5 节。现在没问题了,可以访问我想要的信息了:
|
||||
|
||||
```
|
||||
man 5 passwd
|
||||
```
|
||||
|
||||
然后我被带到了有我需要的信息的手册页。
|
||||
|
||||
`whatis` 是一个方便的工具,可以用简短的一句话告诉你一个命令的作用。想象一下,你想知道 `cal` 是做什么的,而不想查看手册页。只要在命令提示符下键入以下内容。
|
||||
|
||||
```
|
||||
whatis cal
|
||||
```
|
||||
|
||||
你会看到这样的回应:
|
||||
|
||||
```
|
||||
cal (1) - displays a calendar and the date of Easter
|
||||
```
|
||||
|
||||
现在你知道了 `whatis` 命令,我可以告诉你一个秘密 —— 有一个 `man` 命令的等价物。为了得到这个,我们使用 `-f` 开关:`man -f ...`。
|
||||
|
||||
试试吧。在终端提示下输入 `whatis cal`。执行后就输入:`man -f cal`。两个命令的输出将是相同的:
|
||||
|
||||
![whatis cal and man f cal outputs are the same][7]
|
||||
|
||||
#### whereis
|
||||
|
||||
`whereis` 命令的名字就说明了这一点 —— 它告诉你一个程序在文件系统中的位置。它也会告诉你手册页的存放位置。再以 `cal` 为例,我在提示符下输入以下内容:
|
||||
|
||||
```
|
||||
whereis cal
|
||||
```
|
||||
|
||||
我将看到这个:
|
||||
|
||||
![whereis cal output][8]
|
||||
|
||||
仔细看一下这个回答。答案只在一行里,但它告诉我两件事:
|
||||
|
||||
- `/usr/bin/cal` 是 `cal` 程序所在的地方,以及
|
||||
- `/usr/share/man/man1/cal.1.gz` 是手册页所在的地方(我也知道手册页是被压缩的,但不用担心 —— `man` 命令知道如何即时解压)。
|
||||
|
||||
`whereis` 依赖于 `PATH` 环境变量;它只能告诉你文件在哪里,如果它们在你的 `PATH` 环境变量中。
|
||||
|
||||
你可能想知道是否有一个与 `whereis` 相当的 `man` 命令。没有一个命令可以告诉你可执行文件的位置,但有一个开关可以告诉你手册页的位置。在这个例子中使用 `date` 命令,如果我们输入:
|
||||
|
||||
```
|
||||
whereis date
|
||||
```
|
||||
|
||||
在终端提示符下,我们会看到:
|
||||
|
||||
![whereis date output][9]
|
||||
|
||||
我们看到 `date` 程序在 `/usr/bin/` 目录下,其手册页的名称和位置是:`/usr/share/man/man1/date.1.gz`。
|
||||
|
||||
我们可以让 `man` 像 `whereis` 一样行事,最接近的方法是使用 `-w` 开关。我们不会得到程序的位置,但我们至少可以得到手册页的位置,像这样:
|
||||
|
||||
```
|
||||
man -w date
|
||||
```
|
||||
|
||||
我们将看到这样的返回:
|
||||
|
||||
![][10]
|
||||
|
||||
你知道了 `whatis` 和 `whereis`,以及让 `man` 命令做同样(或接近)事情的方法。我展示了这两种方法,有几个不同的原因。
|
||||
|
||||
多年来,我使用 `whatis` 和 `whereis`,因为它们在我的培训手册中。直到最近我才了解到 `man -f ...` 和 `man -w ...`。我确信我看了几百次 `man` 的手册页,但我从未注意到 `-f` 和 `-w` 开关。我总是在看手册页的其他东西(例如:`man -k ...`)。我只专注于我需要找到的东西,而忽略了其他的东西。一旦我找到了我需要的信息,我就会离开这个页面,去完成工作,而不去注意这个命令所提供的其他一些宝贝。
|
||||
|
||||
这没关系,因为这部分就是手册页的作用:帮助你完成工作。
|
||||
|
||||
直到最近我向别人展示如何使用手册页时,我才花时间去阅读 —— “看看还有什么可能” —— 我们才真正注意到关于 `man` 命令的 `-f` 和 `-w` 标记可以做什么的信息。
|
||||
|
||||
不管你使用 Linux 多久了,或者多么有经验,总有一些新东西需要学习。
|
||||
|
||||
手册页会告诉你在完成某项任务时可能需要知道的东西 —— 但它们也有很多内容 —— 足以让你看起来像个魔术师,但前提是你要花时间去读。
|
||||
|
||||
### 结论
|
||||
|
||||
如果你花一些时间和精力在手册页上,你将会取得胜利。你对手册页的熟练程度,将在你掌握 Linux 的过程中发挥巨大作用。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://itsfoss.com/linux-man-page-guide/
|
||||
|
||||
作者:[Bill Dyer][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[wxy](https://github.com/wxy)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://itsfoss.com/author/bill/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://www.britannica.com/biography/Aristotle
|
||||
[2]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2021/06/man-page-example-800x527.png?resize=800%2C527&ssl=1
|
||||
[3]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/05/man_man.png?resize=800%2C455&ssl=1
|
||||
[4]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2021/06/man-page-example-1.png?resize=800%2C527&ssl=1
|
||||
[5]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2021/06/man-page-passwd-command.png?resize=1026%2C676&ssl=1
|
||||
[6]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/05/man-k_example.png?resize=800%2C200&ssl=1
|
||||
[7]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2021/05/whatis_cal_man-f_cal.png?resize=800%2C135&ssl=1
|
||||
[8]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/05/whereis_cal.png?resize=800%2C100&ssl=1
|
||||
[9]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/05/whereis_date.png?resize=800%2C100&ssl=1
|
||||
[10]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2021/05/man-w_date-1.png?resize=800%2C100&ssl=1
|
Loading…
Reference in New Issue
Block a user