man命令详解
1、简介我们都知道,在linux里如果查看帮助的话,可以用man命令。但是如果在man后面加一个数字,可以查看具体的范围。数字意义1用户命令2系统调用3C语言库函数4设备或特殊文件5文件格式和规则6游戏及其他7宏、包及其他杂项8系统管理员相关的命令2、例子...
1、简介
我们都知道,在linux里如果查看帮助的话,可以用man命令。但是如果在man后面加一个数字,可以查看具体的范围。
数字 | 意义 |
1 | 用户命令 |
2 | 系统调用 |
3 | C语言库函数 |
4 | 设备或特殊文件 |
5 | 文件格式和规则 |
6 | 游戏及其他 |
7 | 宏、包及其他杂项 |
8 | 系统管理员相关的命令 |
2、例子
以write举个例子。
2.1 用户命令
我们用man write,可以看到(我们摘抄了前几行):
WRITE(1) BSD General Commands Manual WRITE(1)
NAME
write — send a message to another userSYNOPSIS
write user [tty]DESCRIPTION
The write utility allows you to communicate with other users, by copying lines from your terminal to theirs.
这说明write是一个系统命令。
2.2 系统调用
我们用man 2 write,可以看到:
WRITE(2) Linux Programmer's Manual WRITE(2)
NAME
write - write to a file descriptorSYNOPSIS
#include <unistd.h>ssize_t write(int fd, const void *buf, size_t count);
DESCRIPTION
write() writes up to count bytes from the buffer pointed buf to the file referred to by the file descriptor fd.
这是write作为系统调用的用法。
2.3 标准c库
我们用man 3 write,可以看到:
$ man 3 write
No manual entry for write in section 3
See 'man 7 undocumented' for help when manual pages are not available.
这说明c标准库里没有wirte函数。其实我们可以在标准库里找到fwrite,用man 3 fwrite可以看到:
FREAD(3) Linux Programmer's Manual FREAD(3)
NAME
fread, fwrite - binary stream input/outputSYNOPSIS
#include <stdio.h>size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream);
size_t fwrite(const void *ptr, size_t size, size_t nmemb,
FILE *stream);DESCRIPTION
The function fread() reads nmemb items of data, each size bytes long, from the stream pointed to by stream, storing them
at the location given by ptr.The function fwrite() writes nmemb items of data, each size bytes long, to the stream pointed to by stream, obtaining them
from the location given by ptr.For nonlocking counterparts, see unlocked_stdio(3).
3、补充
man的相关文档都在哪里放着呢?我们可以用manpath命令查看下:
$ manpath
/usr/local/man:/usr/local/share/man:/usr/share/man
在我的电脑上可以看到上面3个目录,只有一个目录下有东西:
$ ls /usr/local/man/
$ ls /usr/local/share/man/
$ ls /usr/share/man/
ar bg ca cy en_AU es fi fr.ISO8859-1 gl hu it ko man1 man5 mhr nb oc pt se sl ta ug zh_CN
ast bn ca@valencia da en_CA et fo fr.UTF-8 he hy ja ku man2 man6 ml ne pa pt_BR shn sq te uk zh_HK
az bo ce de en_GB eu fr fy hi id kk lt man3 man7 ms nl pl ro si sr th uz zh_TW
be bs cs el eo fa fr_CA gd hr io km lv man4 man8 my nn ps ru sk sv tr vi
值得注意的是,里面有man1、man2、一直到man8文件夹。这些文件夹我们可以进去看看,其实和我们上面介绍的man 1 xxx,man 2 xxx,man 3 xxx是一一对应的。
===================================================================================
注意:本文为本人原创,版权所属为个人所有,欢迎转载,但是转载请注明出处。
==================================================================================
更多推荐
所有评论(0)