当今可能我们很多人已经不频繁使用man命令了,取而代之的是更加友好简单的tldr。
存放地址
Linux系统中一切皆为文件,我们首先感兴趣的是,这些manual手册存放在哪里。根据前文 帮你精通Linux:透彻解析Linux的目录树结构 可以简单推测,
-
配置文件在/etc/目录下,具体则为/etc/manpath.config;
-
变量文件在/var/目录下,具体则为/var/cache/man/index.(bt|db|dir|pag)
/etc和/var是linux系统下的最重要的两个目录。
man文件本身存储在/usr/share目录下,/usr/share/man
如何查看特定命令的存储位置呢?需要 -w选项(对应长选项--where)
-
$ man -w time
-
/usr/share/man/man1/time.1.gz
加上选-a(对应--all)则能查到time在所有章节中的位置。
-
$ man -aw time
-
/usr/share/man/man1/time.1.gz
-
/usr/share/man/man2/time.2.gz
-
/usr/share/man/man7/time.7.gz
从结果中看到,在man1(shell commands), man2(system calls)和man7(Miscellaneous)中都有time这个命令。
作为补充,我们也可以用-f选项查看命令所属的sections。
-
$ man -f man
-
man (7) - macros to format man pages
-
man (1) - an interface to the on-line reference manuals
-
-
$ man -f time
-
time (7) - overview of time and timers
-
time (1) - run programs and summarize system resource usage
-
time (2) - get time in seconds
此处的 -f 等价于--whatis
whatis (1) - display one-line manual page descriptions
3.指定查询章节
从 -w 选项中看到了命令的地址,便可以指定章节查询。
-
whatis (1) - display one-line manual page descriptions
-
man 7 time
4.正则查询
man命令最有意思的就是正则查询,心情不好的时候,可以玩上一整天。
从正则查询中,能够获得对全局的掌控感,比如查询systemd有多少个命令:
-
$ man -k ^systemd |nl |tail
-
158 systemd.service (5) - Service unit configuration
-
159 systemd.slice (5) - Slice unit configuration
-
160 systemd.socket (5) - Socket unit configuration
-
161 systemd.special (7) - Special systemd units
-
162 systemd.swap (5) - Swap unit configuration
-
163 systemd.syntax (7) - General syntax of systemd configuration files
-
164 systemd.target (5) - Target unit configuration
-
165 systemd.time (7) - Time and date specifications
-
166 systemd.timer (5) - Timer unit configuration
-
167 systemd.unit (5) - Unit configuration
从结果中国马上获知167这个结果。
或者查询有多少与calendar相关的命令:
-
$ man -k calendar |nl
-
1 cal (1) - displays a calendar and the date of Easter
-
2 calendar (1) - reminder service
-
3 ncal (1) - displays a calendar and the date of Easter
又或者查询全部的ls命令:
-
$ man -k ^ls |nl
-
1 ls (1) - list directory contents
-
2 lsar (1) - list archive file contents
-
3 lsattr (1) - list file attributes on a Linux second extended file system
-
4 lsb_release (1) - print distribution-specific information
-
5 lsblk (8) - list block devices
-
6 lscpu (1) - display information about the CPU architecture
-
7 lsearch (3) - linear search of an array
-
8 lseek (2) - reposition read/write file offset
-
9 lseek64 (3) - reposition 64-bit read/write file offset
-
10 lsetxattr (2) - set an extended attribute value
-
11 lshw (1) - list hardware
-
12 lsinitramfs (8) - list content of an initramfs image
-
13 lsipc (1) - show information on IPC facilities currently employed in ...
-
14 lslocks (8) - list local system locks
-
15 lslogins (1) - display information about known users in the system
-
16 lsmem (1) - list the ranges of available memory with their online status
-
17 lsmod (8) - Show the status of modules in the Linux Kernel
-
18 lsns (8) - list namespaces
-
19 lsof (8) - list open files
-
20 lspci (8) - list all PCI devices
-
21 lspcmcia (8) - display extended PCMCIA debugging information
-
22 lspgpot (1) - extracts the ownertrust values from PGP keyrings and list...
-
23 lstat (2) - get file status
-
24 lstat64 (2) - get file status
-
25 lsusb (8) - list USB devices
5.全局掌控
文章开头就介绍过section 2 中是system-calls命令。我们不免心生好奇,哪些是system-calls呢?
-
$ man -s 2 -k . |nl |tail
-
484 vm86old (2) - enter virtual 8086 mode
-
485 vmsplice (2) - splice user pages to/from a pipe
-
486 vserver (2) - unimplemented system calls
-
487 wait (2) - wait for process to change state
-
488 wait3 (2) - wait for process to change state, BSD style
-
489 wait4 (2) - wait for process to change state, BSD style
-
490 waitid (2) - wait for process to change state
-
491 waitpid (2) - wait for process to change state
-
492 write (2) - write to a file descriptor
-
493 writev (2) - read or write data into multiple buffers
由上可知,系统中共有493个system-calls。我们分析下这一行命令:
-
man -s 2 -k .
短选代表的是长选项--section,-k 是 keyword,等价于 apropos命令,最后的 dot 点 乃是正则表达式里的任意字符的表达方式。
于是,仅仅通过上面的简单命令获得对整个文档乃至整台计算机,整个计算机科学的全局掌控感。我们迅速掠览一遍这9个sections。
6.游戏
man命令有良好的疗愈功效,不妨来看看Kubuntu自带的四个游戏。
-
$ man -s 6 -k . |nl
-
1 intro (6) - introduction to games
-
2 kmahjongg (6) - Mahjongg game for KDE
-
3 (6) - KDE mine sweeper game
-
4 kpat (6) - A highly addictive card game.
-
5 ksudoku (6) - KDE Sudoku games
7.收尾总结
man命令是我们最好的陪伴,帮助满血复活对工作和生活的掌控感。
当今可能我们很多人已经不频繁使用man命令了,取而代之的是更加友好简单的tldr。
(编辑:衡阳站长网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|