您当前的位置: 首页 >  搜索

liaowenxiong

暂无认证

  • 2浏览

    0关注

    1171博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Linux/Unix 如何查看 man 搜索到的手册页(manual page)的位置及复制手册页的内容

liaowenxiong 发布时间:2021-07-23 09:54:20 ,浏览量:2

文章目录
  • 命令 man 是如何搜索手册页的?
  • 如何查看手册页所在的路径
  • 通过管道输出给 vim

命令 man 是如何搜索手册页的?
man uses a sophisticated method of finding manual page files, based on the invocation options and environment 
variables, the  /private/etc/man.conf  configuration  file,  and some built in conventions and heuristics.

First of all, when the name argument to man contains a slash (/), man assumes it is a file specification itself, 
and there is no searching involved.

But in the normal case where name doesn't contain a slash, man searches a variety of directories for a file that
 could be a manual page for the topic named.

If you specify the -M pathlist option, pathlist is a colon-separated list of the directories that man searches.

If you don't specify -M but set the MANPATH environment variable, the value of that variable is the list of the
 directories that man searches.

If you don't specify an explicit path list with -M or MANPATH, man develops its own path list based on the contents 
of the configuration file /private/etc/man.conf.  The MAN-PATH statements in the configuration file identify 
particular directories to include in the search path.

Furthermore, the MANPATH_MAP statements add to the search path depending on your command search path (i.e. your PATH
environment variable).  For each directory that may be in the command search path, a MANPATH_MAP statement specifies
a directory that should be added to the search path for manual page files.  man looks at the PATH variable and adds 
the corresponding directories to the manual page file search path.  Thus, with the proper use of MANPATH_MAP, when 
you issue the command man xyz, you get a  manual  page  for the program that would run if you issued the command xyz.
 

In  addition,  for  each directory in the command search path (we'll call it a "command directory") for which you do 
not have a MANPATH_MAP statement, man automatically looks for a manual page directory "nearby" namely as a 
subdirectory in the command directory itself or in the parent directory of the command directory.

You can disable the automatic "nearby" searches by including a NOAUTOPATH statement in /private/etc/man.conf.


In each directory in the search path as described above, man searches for a file named topic.section, with an optional 
suffix on the section number and possibly a compression suffix.   If it doesn't find such a file, it then looks in any 
subdirectories named manN or catN where N is the manual section number.  If the file is in a catN subdirectory,man 
assumes it is a formatted manual page file (cat page).  Otherwise, man assumes it is unformatted.  In either case, if 
the filename has a known  compression  suffix  (like.gz), man assumes it is gzipped.

If you want to see where (or if) man would find the manual page for a particular topic, use the --path (-w) option.

如何查看手册页所在的路径

如果您想查看某个特定主题的手册页在哪里(或是否在哪里),请使用 --path-w 选项。例如,我想知道命令man的手册页文件在哪里,可以输入下面的命令:

lwxdeMacBook-Air:cmd lwx$ man -w man
/usr/share/man/man1/man.1
lwxdeMacBook-Air:~ lwx$ cp /usr/share/man/man1/man.1 /Users/liaowenxiong/desktop # copy to desktop to look look
通过管道输出给 vim

执行以下的命令就可以用 vim 的快捷键/命令来复制里面的内容:

man command_name | vim
关注
打赏
1661566967
查看更多评论
立即登录/注册

微信扫码登录

0.1806s