注:本文为 “Linux man 手册” 相关文章合辑。
略作重排。
man 手册常用命令
1. 查看和搜索手册页
- 查看特定软件包的手册页,并使用
grep
命令过滤出包含特定关键字的行:
man <package> | grep <keyword>
- 在整个系统的手册页中搜索包含关键字的描述:
man -k <keyword>
- 搜索与关键字相关的命令名称和描述:
apropos <keyword>
- 显示指定命令的简要描述:
whatis <command>
2. 手册页中的搜索操作
向前搜索:
/
:进入搜索模式,输入要搜索的文本,按回车键开始搜索。n
:在搜索结果中向前跳转到下一个匹配项。
向后搜索:
?
:进入反向搜索模式,输入要搜索的文本,按回车键开始搜索。N
:在搜索结果中向后跳转到上一个匹配项。
退出搜索模式:
Esc
或Ctrl + C
:退出搜索返回到正常阅读模式。
3. 说明
whatis <command / keyword>
等价于man -f <command / keyword>
apropos <command / keyword>
等价于man -k <command / keyword>
若使用 whatis
和 apropos
命令,需以 root
身份创建 whatis
数据库:
[root@www ~] # makewhatis
Linux 中 man 手册的安装以及使用详解
小道克已于 2023-03-14 05:44:33 修改
man 手册是什么
man
是 manual
的简称,中文可称为手册。man
手册是 Linux 系统提供的一种帮助手册。
man 手册用途
当需要查看某个命令的具体参数和使用方法时,无需在网上搜索,只需使用 man
命令,即可查询出所需命令的具体参数及使用方法。
man 手册安装
首先输入 man
并回车,若出现下列错误,请参阅解决方案:
- This system has been minimized by removing packages and content that are not required on a system
https://blog.csdn.net/qq_46140800/article/details/114967350
若出现以下所示内容:
则可继续进行下一步操作。
在命令行中输入以下命令来安装 man
手册:
apt-get install man-db
输入 y
进行安装,等待安装完成。
接下来检查是否安装完成,输入命令:
man echo
// 此处查询的是 echo 命令,作为测试,可使用不同的命令进行。
如图所示,若查询到 echo
命令的具体参数,则表示安装成功。
man
手册的安装至此结束。
man 手册如何使用
以下通过举例进行讲解:
首先敲击命令:
man mkdir
# man 命令的名称
查看关于 mkdir
命令的参数及使用方法:
MKDIR (1) User Commands MKDIR (1)
NAME
mkdir - make directories
SYNOPSIS
mkdir [OPTION]... DIRECTORY...
DESCRIPTION
Create the DIRECTORY (ies), if they do not already exist.
Mandatory arguments to long options are mandatory for short options too.
-m, --mode=MODE
set file mode (as in chmod), not a=rwx - umask
-p, --parents
no error if existing, make parent directories as needed
-v, --verbose
print a message for each created directory
-Z set SELinux security context of each created directory to the default type
--context [=CTX]
like -Z, or if CTX is specified then set the SELinux or SMACK security context to CTX
--help display this help and exit
--version
output version information and exit
AUTHOR
Written by David MacKenzie.
REPORTING BUGS
GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
Report mkdir translation bugs to <https://translationproject.org/team/>
COPYRIGHT
Copyright (C) 2018 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.
SEE ALSO
mkdir (2)
Full documentation at: <https://www.gnu.org/software/coreutils/mkdir>
or available locally via: info '(coreutils) mkdir invocation'
man
手册的目录结构:
名称 | 含义 |
---|---|
NAME | 命令名称 |
SYNOPSIS | 命令语法(摘要) |
DESCRIPTION | 命令的详细描述 |
AUTHOR | 命令的作者 |
REPORTING BUGS | 报告错误的途径 |
COPYRIGHT | 版权信息 |
SEE ALSO | 相关文档或命令 |
通常在查询命令时,关注的是第二项和第三项。
section
手册内容通常分为多个部分,左上角的 (1)
表示该命令所属的 section
。man
手册分为以下 9 个 section
:
section 序号 | 含义 |
---|---|
1 | 可执行文件或 Shell 命令 |
2 | 系统调用(内核函数) |
3 | 库函数 |
4 | 特殊文件(通常在 /dev ) |
5 | 文件格式(如 /etc/passwd ) |
6 | 游戏 |
7 | 杂项(包括宏包) |
8 | 系统管理员命令(通常为 root 用户) |
9 | 内核例程(非标准例程) |
如需查看 section
的具体内容,可以使用命令:
man man
如上图所示,mkdir
命令是在可执行文件这个section
的。需要知道的是,如果没有指定 man
在哪个section
中查找,man
将会按照默认的顺序查找这些section
中的命令,只返回含有该命令的第一个文档;如果指定了section
,则只会在指定section
中寻找该命令。所以有时候直接使用 man
而不指定section
,可能不会找到想要的文档。
如果需要指定查询某个 section
中的命令,可以使用以下格式:
man [section] [command]
例如:
man 5 passwd
这里指定 section
序号 为 5
,所以会在第五section
中寻找符合要求的文档。
分析具体结构
依旧以 mkdir
为例:
1、NAME
部分(名称)
mkdir
是命令的名称,含义为:make directories
,中文意思是:创建目录。
2、SYNOPSIS
部分(摘要,命令语法)
mkdir [OPTION]... DIRECTORY...
“OPTIONS
” 左右有 “[
” 和 “]
”,表示这些参数不是必须的,但可以使用。对应的 DIRECTORY
两边没有 “[]
”,表示这是必须要加的参数。
另外,它们后面都有 “…
”,表示这些参数可以重复使用多次。
3、DESCRIPTION
部分(描述)
Create the DIRECTORY (ies), if they do not already exist.
中文意思为:如果目录不存在,则创建目录。
文档中有几个具体的运行命令,此处不再一一列举。
4、AUTHOR
命令的作者。
5、REPORTING BUGS
(已报告的错误)
GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
Report mkdir translation bugs to <https://translationproject.org/team/>
分别是在线帮助以及报告错误的网址。
6、COPYRIGHT
(版权)
Copyright (C) 2018 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.
7、SEE ALSO
(查看相关信息的位置)
mkdir (2)
Full documentation at: <https://www.gnu.org/software/coreutils/mkdir>
or available locally via: info '(coreutils) mkdir invocation'
大意为在section
2 中也有相关的文档。
man 手册页的基本操作
此处仅介绍了两个命令,如需使用更多命令,可以使用命令:
man man
来查看更多 man
命令的参数。
1. 查找信息
如果已经进入文档页面,那么可以使用 “/
” 键进行正则表达式的搜索。
如果不知道要打开的文档的名称,可以使用命令:
man -k
例如 man -k mkdir
2. 退出 man 手册
按下键盘上的 “q
” 键即可退出 man
手册。
via:
- Linux 中 man 手册的安装以及使用详解 - CSDN 博客 小道克已于 2023-03-14 05:44:33 修改
https://blog.csdn.net/qq_46140800/article/details/114966124