unix 命令行 man
Linux man command is the number one helper to get more detailed information about Linux commands. There are different alternatives like info but man is a de-facto command for help. In this tutorial, we will look at various usage examples of the man command.
Linux man命令是获得有关Linux命令的更多详细信息的第一助手。 有很多其他选择,例如info,但是man是事实上的帮助命令。 在本教程中,我们将看一下man命令的各种用法示例。
man命令语法 (man Command Syntax)
We will use following syntax for man
command.
我们将对man
命令使用以下语法。
man OPTION TERM
- TERM is the command, utility, topic we want to open its man page. TERM是我们要打开其手册页的命令,实用程序,主题。
- OPTION is optional and used to provide optional to the man command. OPTION是可选的,用于为man命令提供可选的选项。
查看手册页 (View Man Page)
The most common usage for man command is listing a command, tool, library usage simply. We will list the manual for ls
command like below.
man命令最常见的用法是简单列出命令,工具和库的用法。 我们将列出ls
命令的手册,如下所示。
$ man ls
手册页部分(Man Page Sections)
Manual pages are categorized into sections. Each command, tool, library have a section. Categorization is made according to the relevance of command, tool, library. Each section has a number from 1 to 9.
手册页分为几部分。 每个命令,工具,库都有一个部分。 根据命令,工具,库的相关性进行分类。 每个部分的编号从1到9。
- Executable programs or shell commands 可执行程序或外壳命令
- System calls (functions provided by the kernel)系统调用(内核提供的功能)
- Library calls (functions within program libraries) 库调用(程序库中的函数)
- Special files (usually found in /dev) 特殊文件(通常在/ dev中找到)
- File formats and conventions eg /etc/passwd 文件格式和约定,例如/ etc / passwd
- Games 游戏类
- Miscellaneous (including macro packages and conventions), e.g. man(7), groff(7)杂项(包括宏包和约定),例如man(7),groff(7)
- System administration commands (usually only for root) 系统管理命令(通常仅用于root用户)
- Kernel routines [Non-standard] 内核例程[非标准]
查看特定部分的手册页 (View Man Page For Specific Section)
Sometimes there may be more than one tutorial about some expression. But those manual sections are different. For example print
have more than one manual. We will look for section 1
manual with the example below.
有时,关于某种表达方式的教程可能不止一个。 但是这些手册部分是不同的。 例如, print
有不止一本手册。 我们将通过以下示例查找第1
节手册。
$ man 1 printf
列出命令的节(List Sections For A Command)
We may want to list sections for a command, library, or function. We will use man pages file to search and list. In the example, we will look printf
command manual pages.
我们可能要列出命令,库或函数的部分。 我们将使用手册页文件进行搜索和列出。 在示例中,我们将查看printf
命令手册页。
$ man -aw printf
We can get section numbers from file name and directory name.
我们可以从文件名和目录名获取节号。
查看命令的所有手册页 (View All Man Pages For A Command)
Another usage form for man pages is viewing all pages in a single command. Manual pages will be printed in a string mode. In order to quit from pages use q
shortcut. We will use -a
option to list all manual pages for printf
command.
手册页的另一种用法是在一个命令中查看所有页面。 手册页将以字符串模式打印。 为了退出页面,请使用q
快捷键。 我们将使用-a
选项列出printf
命令的所有手册页。
$ man -a printf
在浏览器中查看手册页 (View Man Page In Browser)
Another useful feature is viewing man pages in a browser. This is a more human-friendly way to read manuals but keep in mind that this will require a GUI desktop. First, we will set the BROWSER
variable for the command line interface bash and then use -H
parameter with the related command which is printf
in this situation.
另一个有用的功能是在浏览器中查看手册页。 这是一种更人性化的手册阅读方式,但请记住,这将需要GUI桌面。 首先,我们将为命令行界面bash设置BROWSER
变量,然后将-H
参数与相关命令(在这种情况下为printf
一起使用。
$ export BROWSER=/usr/bin/firefox
$ man -H printf
搜索手册页“ NAME”部分 (Search Man Page NAME Section)
Man pages have different sections too. These are used to define part names. Here are these sections.
手册页也有不同的部分。 这些用于定义零件名称。 这些是这些部分。
NAME
contains the name of the command and short explanationNAME
包含命令名称和简短说明SYNOPSIS
contains usage syntaxSYNOPSIS
包含用法语法DESCRIPTION
contains a more detailed explanationDESCRIPTION
包含更详细的说明OPTIONS
contains all options about commandOPTIONS
包含有关命令的所有选项HISTORY
contains history about the command and personsHISTORY
记录包含有关命令和人员的历史记录
$ man -f printf
搜索手册页名称和说明部分(Search Man Page NAME and DESCRIPTION Section)
In the previous example, we have only searched in the NAME
section. We may want to get more results and search in the DESCRIPTION
section too. We will provide -k
option like below.
在上一个示例中,我们仅在NAME
部分中进行了搜索。 我们可能希望获得更多结果,并在DESCRIPTION
部分中进行搜索。 我们将提供如下的-k
选项。
$ man -k printf
翻译自: https://www.poftut.com/man-command-usage-examples-linux-unix/
unix 命令行 man