man命令是linux下查找shell命令、函数等使用方法的利器。最简单的使用方式是man <the thing you want>。掌握上面那条命令应该也可以满足80%的使用场景了。这里记录一些更加深入的man命令使用的方法,如果还不能满足查询需求,就只能man man再深挖了。

man <section> <pagename>
这条命令可以在指定的section中去查询想要搜索的指南,因为一个pagename可能对应多个分属不同section的page,例如直接man signalman 7 signal出来的内容是完全不一样的。man具有的常用section如下

1 Executable programs or shell commands
2 System calls (functions provided by the kernel)
3 Library calls (functions within program libraries)
4 Special files (usually found in /dev)
5 File formats and conventions, e.g. /etc/passwd
6 Games
7 Miscellaneous (including macro packages and conventions), e.g. man(7), groff(7)
8 System administration commands (usually only for root)
9 Kernel routines [Non standard]

man -a <pagename>
这条命令可以显示关于要查找的这个page的所有内容,不过是一页一页显示,并不是很方便,使用man -aw <pagename>可以看到全部的信息路径。

~$ man -aw signal
/usr/share/man/man2/signal.2.gz
/usr/share/man/man7/signal.7.gz

man -k <regex>
这条命令可以按正则表达式在所有section的所有page中去搜索,返回匹配的page和其简单的介绍

~$ man -k .*open.*
openocd (1)          - A free and open on-chip debugging, in-system programming and boundary-scan testing tool for ARM and MIPS systems
RAND (7ssl)          - the OpenSSL random generator
Ast_helper.Opn (3o)  - Opens
Ast_iterator (3o)    - Ast_iterator.iterator enables AST inspection using open recursion.
authorized_keys (5)  - OpenSSH daemon
CA.pl (1ssl)         - friendlier interface for OpenSSL certificate programs
catclose (3)         - open/close a message catalog
catopen (3)          - open/close a message catalog
config (5ssl)        - OpenSSL CONF library configuration files
creat (2)            - open and possibly create a file
crypto (7ssl)        - OpenSSL cryptographic library
dbopen (3)           - database access methods
des_modes (7ssl)     - the variants of DES and other crypto algorithms of OpenSSL

man -f <keyword>
这个用法等价于whatis <keyword>,可以从系统中搜索出和keyword相关的指南。

~$ man -f Git
Git (3pm)            - Perl interface to the Git version control system
git (1)              - the stupid content tracker

~$ whatis git
Git (3pm)            - Perl interface to the Git version control system
git (1)              - the stupid content tracker

man -Kw <regex>
全局搜索正则表述的关键字,把结果路径显示出来,这个搜索有点慢。

~$ man -Kw SIGILL
/usr/share/man/man1/python3.8.1.gz
/usr/share/man/man1/python3.8.1.gz
/usr/share/man/man3/Stdlib.Sys.3o.gz
/usr/share/man/man3/Sys.3o.gz
/usr/share/man/man2/sigaction.2.gz
/usr/share/man/man2/sigaction.2.gz
/usr/share/man/man2/signal.2.gz
/usr/share/man/man2/sigprocmask.2.gz
/usr/share/man/man2/sigprocmask.2.gz
/usr/share/man/man7/signal.7.gz

以上这些命令应该可以cover住90%以上的man使用场景。

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐