Is there a way to follow the links mentioned in a man page? For example, here's the man page for ps
; how do I access the underlined link circled in red in the screenshot: top(1)
?
11 Answers
Man pages date back to Unix First Edition. While hypertext had been invented, it was still in infancy; the web was two decades away, and the manual was an actual printed book, often with one command per page if they fit (that's why they were called pages).
The format used for manual pages has evolved somewhat since then, but most pages aren't really designed for hypertext, and the default man
program doesn't support it (it's just a plain text viewer, with hacks to support some basic formatting). There are however man page viewing programs that reconstruct some hyperlinks, mainly links to other man pages, which are traditionally written in the form man(1)
where man
is the name of the man page and 1
is the section number:
- tkman, a GUI man page viewer with hyperlinks
- WoMan (wiki, man comparsion, formerly), a man page browser for Emacs, supporting hyperlinks
- man2html, a man to HTML converter (plus a web browser to read the result)
You can browse the manual pages of several operating systems, converted to HTML by man2html
or similar tools, on a number of sites online, for example:
- Arch Linux
- CentOS
- Debian
- FreeBSD (and a bunch of other collections)
- macOS: archive from 10.9 Mavericks, recent version at unix.com, partial copy at ss64.com
- MINIX 3
- NetBSD
- OpenBSD
- Solaris 10, Solaris 11, other Solaris versions
- Ubuntu
- Unix 1st edition, Unix 6th edition, Unix 8th edition
Some time after man pages had become the established documentation format on unix and some time before the web was invented, the GNU project introduced the info documentation format, more advanced than man while sticking to simple markup designed for text terminals. The major innovation of info compared to man was to have multi-page documentation with hyperlinks to other pages. Info is still the prefered documentation format for GNU projects, though most Info pages are generated from a Texinfo source (or sometimes other formats) that can also generate HTML. When info documentation for a program exists, it's often the main manual, while the man pages only contain basic information about command line arguments.
-
8Great answer! Also worth mentioning is that there is another mode for man pages in Emacs, the one (at least I) get by just
M-x man
(andC-h v mode-name
isMan
): at least in one aspect, it is superior toWoMan
because it displays tables (screenshot). Of course, it is hyperlinked as well. Mar 6, 2013 at 22:38 -
6The info program user interface feels just wrong and counter-intuitive. I haven't seen anyone using that. Jan 16, 2018 at 1:53
-
2@PavelŠimerda> The info program user interface feels just wrong and counter-intuitive. < Emm, compared to what? To less(1) (which is default pager for man(1) in GNU) — that thing, where you have to recall how to scroll back, since <backspace> is not bound (and <pgup> might not work at all)? The primary key is
b
, by that way. To a user of which interface paradigm this might be intuitive? Feb 10, 2018 at 22:40 -
@PavelŠimerda> I haven't seen anyone using that. < Always use info(1) for reading manpages when got locked in a text terminal for the exact reason, that unlike less(1) it does convert dumb
page(N)
links into hyperlinks. Was quite suprised that is was not mentioned in Gilles’ answer in that quality. Feb 10, 2018 at 22:41 -
It could be useful to remind that in
info
, one can follow links (weirdly formatted as*link text::
) by moving the cursor on it (or Tab) and hitting Enter. Also it seems to me that info accepts all sorts of emacs commands, but it's too tricky for me (I use vim). Dec 16, 2020 at 18:08
First of all, it's not a link. It's just an underline. Man pages are just text documents with a little bit of simple formatting that a terminal can handle. The underline is just a highlight, there is no "link" involved.
The normal man
command is just a text formatter. In fact the man
command doesn't even display the text, man
just formats the information stored in the man page file[1] and sends the formatted output to another program (usually less
) that displays the formatted output to the screen. These display programs have no concept of links.
There are some special documentation readers that might be able to look at formatting like that and make an educated guess that such a highlight might indicate that there is a related man page that could be pulled up and create a link, but I don't know which ones do. Perhaps pinfo
?
If you want web like formatting with hyperlinks you can find almost any UNIX man page online with links added in. Try typing man [anything]
into google and you will almost certainly get one in the first couple hits.
In the case of your example, the visual highlighting is a clue that that is another program name that has it's own man page that you can easily pull up. Try man 1 top
. The 1 indicates the section of the man pages to look in. See this question for an explanation of the sections: What do the numbers in a man page mean?
[1] If you open the man
page file in a text editor, you will see the raw man
page that is not formatted for easy reading. The raw man
page is written in a markup language called troff
. For more information on troff
and how to write a man
page see: https://liw.fi/manpages/ .
-
Any idea why it is
man 1 top
?? I mean it should be something likeps 1 top
because I found the link on the man page forps
. "man 1 top" doesn't make sense to me. Please clarify.– its_meAug 5, 2011 at 20:20 -
There are also some resources that make man pages available on the internet, with references replaced by href's, which are clickable.– gabe.Aug 5, 2011 at 20:22
-
1If you want to follow
top(1)
"link", you need to opentop
manual page from 1st section. For more information about sections see man(1).ps 1 top
does not makes any sense, since you'll just runps
command with some strange to it params.– rvsAug 5, 2011 at 20:23 -
2@Aahan it's man 1 top because you want to see the manual page for the top command in the 1st section of the online manual pages. The reference top(1) means just that, top in the 1st section of the manual pages. To see that, you type "man 1 top" at the prompt. See "man man"– gabe.Aug 5, 2011 at 20:24
-
1@Aaran: The "sections of the manual cover different topics. Section 1 is user commands (stuff you type at the prompt) section 2 is system calls and so on. Some strings appear n more than one section. On the machine I am on right now
readlink
appears in section 1 and section 2 andprintf
in sections 1 and 3. If you just typeman command
, man trys sections in numeric order and displays the first it finds, or you can be specific withman # command
, which you have to do to get the documentation for thereadlink
system call. Aug 6, 2011 at 14:26
I recommend w3mman
, the system’s manual pager through the w3m command-line browser. It colors links and enables tabbing through them
You can try it by installing the w3m
package, which is available in most software repositories and Cygwin.
-
1A late reply that adds some answer to the question that is not mentioned yet, it never a problem! Welcome at Unix&Linux StackExchange!– BernhardDec 14, 2012 at 9:48
-
w3mman
is also provided with the default Macportsw3m
installation. It's great :) Thanks!– user6860Sep 8, 2014 at 0:58
Let me try to interpret your question a bit more in a sense in which I try to follow your workflow. What you probably would like to have is a key combination within a man
page that leads you directly to the underlined commands you are reading about. So, not having to install something else, nor opening up another console and forgetting the exact syntax for example.
This simplest solution is the exclamation mark (if you are using less
to display the man pages) and you want to go to the underlined top
:
!man top
Or
!man 1 top
You will have to close them all by pressing q
multiple times. Note also that this won't work if LESSSECURE=1
is set as environmental variable which would make run less
in secure mode and not allow you to use !
. It will tell you something like "Command not available".
-
This is not an answer to the question. Saying this is "a key combination" is gross dishonesty to say the least. First it's not dynamic, you have to type the name of the word under the cursor manually, so it's strictly not a key combination since it changes every for every different target. Secondly, since you're resorting to technicalities, you're spawning another process so this is not "within a man page". We could make the exact same argument saying "You can use the key combination
qman 1 top
from within the man page!" With this in mind, I hope you can realize the bad faith of your post.– adamencyOct 5 at 23:21
I have a (couple of) hack(s).
hack 1
Put this in your ~/.bashrc or your ~/.zshrc
function man(){
for arg in "$@"; do
vim -c 'execute "normal! :let no_man_maps = 1\<cr>:runtime ftplugin/man.vim\<cr>:Man '"${arg}"'\<cr>:wincmd o\<cr>"'
done
}
Screenshot..
Asciinema..
https://asciinema.org/a/130131
Now..
when you type
man vim
, for example, it will open up this man page in vim- if you type
man man vim
, for example, it will first openman
's manual and after you exit vim, it will openvim
's manual
- if you type
when you press K (that's capital
k
) when you are on another man page at the bottom (the SEE ALSO section), you will jump to this manual (unfortunately inside of a less pager -- this is because we havelet no_man_maps = 1
; if you don't do that, then vim will forceq
to be:q
and you will be unable to record a macro easily, and vim may behave wonkily in other ways).- exiting this second manual you have entered will bring you back to the previous manual you were viewing
you get very pretty syntax highlighting since you have loaded ftplugin/man.vim and the ft is (automatically) set to
man
.you can copy and paste, navigate freely in vim, and even modify the buffer and
:w ~/usefulfile
. You can do everything you would normally do in vim, including record macros, yank to clipboard with"+y
(if you have+clipboard
), etc, etc.
I find it much nicer than less.
The only minor setback I have found (which still exists if you use less as your pager) is if you want to have multiple manuals open in one vim session. I don't really see a way to do this.
A few notes:
if you try to save the buffer, you will get
E382: Cannot write, 'buftype' option is set
- I like that you cannot save as it prevents accidentally saving it
you can still save like
:w /tmp/man.man
- if you save it with a
.man
extension, then opening it up will set the filetype toman
for you - if you do not save it with a
.man
extension, you can just set the ft toman
by running:set ft=man
- if you save it with a
if you need to do things when opening up man pages you can use
autocmd VimEnter *.~ echom 'hooray, we are using vim for man pages!'
, for example.I have put the following in my vimrc so that I can press K to try to open manual, and then press G to go back to previous manual:
augroup man
autocmd!
autocmd VimEnter *.~ nnoremap B :execute "normal! `Z"<cr>
autocmd VimEnter *.~ nnoremap <buffer> K :execute "normal! mZyiw:Man \<lt>c-r>\"\<lt>cr>"<cr>
augroup END
hack 2
put this in your ~/.bashrc or ~/.zshrc
function man(){
declare -a args
for arg in "$@"; do
command man "$arg" > "/tmp/${arg}.man"
args+=("/tmp/${arg}.man")
done
vim "${args[@]}"
}
Screenshot..
Asciinema..
https://asciinema.org/a/9Q6Si90Pi46cDVUknxFxfIwsv
This solves problem that hack 1 and less face (now you can view multiple manuals in one buffer), but it is less elegant.
Notes:
IMPORTANT if you want hack2 to work, then you must put
:let no_man_maps = 1
in your~/.vimrc
. This is because vim will source.../vim80/man.vim
andq
will be forcibly remapped to:q
.there is more clean up involved (now you store every manual to /tmp/*.man)
you can now, however, view multiple man pages in one session, as noted above
if you press K, you will still open a new vim session, however
- if you want you can bind an autocmd (using an autocmd like the one above) to do something like
autocmd VimEnter man.~ nnoremap <buffer> K :execute "normal! Byt(:silent !man \<c-r>\" > /tmp/\<c-r>\".man\<cr>:edit /tmp/\<c-r>\".man\<cr>"
or something crazy like that (untested)
- if you want you can bind an autocmd (using an autocmd like the one above) to do something like
-
apologies for badly colored asciinema. The colors look a lot nicer in my terminal.– DylanJul 22, 2017 at 23:19
Specifically for Ubuntu, there is Yelp. It's installed by default and is by default able to display manual pages, although the invocation to do so, is not the same as that of the man
command; an alias or a shell function can work around the latter point (depends on your shell).
yelp 'man:exit'
It will default to a section in a way I don't know. Reminder: to get the sections list for a manual topic, use whatis
, as in whatis exit
.
To request Yelp to display a manual page from a specific section, say 2, do:
yelp 'man:exit(2)'
Issues: yelp has bugs and be prepared to get multiple errors output when invoking it from the command line. There also, an alias or a custom shell function can help redirecting all errors to /dev/null
Just thought I'd add my 2 pence.
I'm using the following to view man pages, I've aliased man to the below command (which if you use zsh will still provide autocomplete).
man --html='lynx --cfg=~/.lynx.cfg' <manpage>
With the following in ~/.lynx.cfg
which sets up keys for easy navigation and sets q to quit, like in man. I had to copy the HELPFILE
entry from the main /etc/lynx/lynx.cfg
otherwise the help was not displaying properly.
KEYMAP:k:UP_TWO # Move display up two lines
KEYMAP:j:DOWN_TWO # Move display down two lines
KEYMAP:K:UP_HALF # Move display up half a page
KEYMAP:J:DOWN_HALF # Move display down half a page
KEYMAP:h:PREV_LINK # Move to the previous link or page
KEYMAP:l:NEXT_LINK # Move to the next link or page
KEYMAP:q:ABORT
HELPFILE:file://localhost/usr/share/doc/lynx-common/lynx_help/lynx_help_main.html.gz
Note: you will need to install the groff package for this to work.
sudo apt install groff
The result is quite nice, since man is doing the conversion to html I expect its the best option for getting links working correctly.
-
Thanks! I like the color scheme, it seems more convenient to read with lynx than with yelp. Also the useful captions menu on top.– d9kJul 22, 2021 at 11:36
You can set vim
(or nvim
) as the viewer for the man page:
export MANPAGER='nvim +Man!'
Then you can use CTRL-]
to follow a tag, and CTRL-t
or CTRL-o
to go back a tag.
For more info, read the plugin's documentation and do :h tag
in nvim
.
Like they said, it wasn't designed for it.
You can use info man
and then hit enter once you're under SEE ALSO section on your item.
info - read Info documents
Although w3mman is a solution to follow links, does not use all the screen (at least on ubuntu 12.10)
I prefer to use:
$ sudo -i
# apt-get install w3m man2html
# exit
$ alias man=' hman -P w3m'
add the last command to ~/.bash_aliases or similar startup script to get it on every session.
The -P w3m is because first browser to hman is lynx or sensible-browser but I prefer w3m
hman is a tool bundled on html2man. See this
If exit with confirmation is annoying to you, as to me is use this
I was able to use the --html
argument to man
in order to open it in the browser defined by $BROWSER environment variable, so:
BROWSER=google-chrome man ps --help
I'm using Fedora. Not sure if this works for your distro, please test and report in comments.
-
-
OK, the package
groff
needs to be installed. Thegroff
command may be there while the package of the same name is not (the command comes withgroff-base
, not the fullgroff
package). I doman --html="surf file%c//%s" <command>
, and it's fine. There is very‑very limited hypertext though :-/ .– Hibou57Aug 12, 2014 at 8:45
man is an interface to the on-line reference manuals
which (if I am not wrong) means it should be pulling all the info from some webpage on the internet, right? So, anyone has a clue as to what the http:// link is?