本文简要说明linux man的使用

man是linux系统中帮助我们查看命令和函数使用方法的强大命令,今天在自己的系统上使用突然发现无法查阅一些libc的标准函数,修复后顺便记录一下man的简单使用方法。

安装man page 链接到标题

下面是libc和posix常用的page,man memcpy的时候找不到就先用下面命令安装

sudo apt-get install manpages-de manpages-de-dev manpages-dev glibc-doc manpages-posix-dev manpages-posix manpages manpages-dev  manpages-posix manpages-posix-dev

使用 链接到标题

man <CMD/API>即可,例如 查看memcpy函数的使用方法

man memcpy

MEMCPY(3)                                                             Linux Programmer's Manual                                                            MEMCPY(3)

NAME
       memcpy - copy memory area

SYNOPSIS
       #include <string.h>

       void *memcpy(void *dest, const void *src, size_t n);

DESCRIPTION

查看date shell命令的使用方法

man date

NAME
       date - print or set the system date and time

SYNOPSIS
       date [OPTION]... [+FORMAT]
       date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]

DESCRIPTION
       Display the current time in the given FORMAT, or set the system date.

如果同一个符号即是函数又是shell命令怎么办,例如mount,我们先man man看一下

描述
       man 是系统的手册分页程序。指定给 man 的 页 选项通常是程序、工具或函数名。程序将显示每一个找到的相关 手册页。如果指定了  章节,man  将只在手册的指定  章节  搜
       索。默认将按预定的顺序查找所有可用的  章节 (默认是“1 n l 8 3 2 3posix 3pm 3perl 3am 5 4 9 6 7”,除非被 /etc/manpath.config 中的 SECTION 指令覆盖),并只显示找
       到的第一个 页,即使多个 章节 中都有这个 页面。

       下表显示了手册的 章节 号及其包含的手册页类型。

       1   可执行程序或 shell 命令
       2   系统调用(内核提供的函数)
       3   库调用(程序库中的函数)
       4   特殊文件(通常位于 /dev)
       5   文件格式和规范,如 /etc/passwd
       6   游戏
       7   杂项(包括宏包和规范,如 man(7),groff(7))
       8   系统管理命令(通常只针对 root 用户)
       9   内核例程 [非标准

可以看到如果执行man mount会按顺序有线显示其shell命令的使用方法,我们可以通过指定page号显示其函数的使用方法

man 2 mount

NAME
       mount - mount filesystem

SYNOPSIS
       #include <sys/mount.h>

       int mount(const char *source, const char *target,
                 const char *filesystemtype, unsigned long mountflags,
                 const void *data);

DESCRIPTION
       mount() attaches the filesystem specified by source (which is often a pathname referring to a device, but can also be the pathname of a directory or file, or
       a dummy string) to the location (a directory or file) specified by the pathname in target.