47

How can I make manpages (from the man command) open in a web browser for easier navigation?

kiri
  • 28,246
  • 16
  • 81
  • 118
  • http://linux.die.net/man/ -- that way you have most everything you can dream of. There are scripts to transform manuals into HTML, but unless you transform them all, links won't work as expected. Also readability is exceptional in a console too. Maybe you meant better navigation? – Alexis Wilke Aug 30 '13 at 09:14
  • 2
    @kevin I'd rather use a web browser (I'm more familiar with it) and I found that gman would become unresponsive after opening a page – kiri Aug 30 '13 at 09:51
  • understood. gman can use a browser, but I see your point. plus it does lack navigation ability.I had just posted that as you added to your question. ;-) you could also take a look at the dwww package. – Kevin Bowen Aug 30 '13 at 09:54
  • 1
    This may not be your solution, but in knoqueror, you could type man:> to access the man pages in a browser. This will require you to install the kde libs. – crafter Oct 04 '13 at 08:59
  • There's another alternative to http://linux.die.net to view man pages preprocessed and beautified online: http://man7.org/linux/man-pages/index.html – Murphy Dec 08 '17 at 09:29

4 Answers4

60

Using the man program

Looking at the manpage of man,

man man

There is the -H option, or its equivalent --html which will generate the HTML for the manual and open them in the browser.

This option will cause groff to produce HTML output, and will display that output in a web browser. The choice of browser is determined by the optional browser argument if one is provided, by the $BROWSER environment variable, or by a compile-time default if that is unset (usually lynx). This option implies -t, and will only work with GNU troff.

So to open any man page in the browser just use:

man -Hfirefox <command>

or

man --html=firefox <command>

Both are the same.

You can use firefox, google-chrome, chromium-browser or any other in place of the firefox word.

Select a default browser permanently

Before calling the man command, use the following command:

export BROWSER=firefox

This way, you can just use man -H or man --html without specifying the browser each time.

man -H ls

You can also add the previous export command to your ~/.bashrc so you won't have to type it each time you open a new terminal and try using man -H

Troubleshoot

If you got an error saying something like this:

man: command exited with status 3: /usr/bin/zsoelim | /usr/lib/man-db/manconv -f UTF-8:ISO-8859-1 -t UTF-8//IGNORE | preconv -e UTF-8 | tbl | groff -mandoc -Thtml

You will need to install the groff package.

sudo apt-get install groff

Using Yelp

If a choice of browser is not relevant, you can use the yelp command which offers navigation through the man pages.

yelp man:<command>
# example: yelp man:ls

Using the Ubuntu Manpage Repository

You can also visit https://manpages.ubuntu.com/ and check almost all man pages there. All versions of the man pages for all the Ubuntu versions are available there. It also features a search functionality.

Of course, the downside of using the website is that you can't access it without being connected to the Internet.

Dan
  • 13,119
  • You can use the command xdg-open which would open the systems defalt too – exussum Aug 30 '13 at 13:56
  • 1
    and you would need groff installed – exussum Aug 30 '13 at 14:04
  • @user1281385 I was going to mention it, but it has a few issues. For example, my default is Firefox. If I try to use it, and I already have Firefox open, it shows me the error which says Firefox is already running, but is not responding. To open a new window, you must first close the existing Firefox process, or restart your system. I did mention installing groff – Dan Aug 30 '13 at 14:06
  • manpages.ubuntu.com seems useful! – Stefano Sep 04 '13 at 11:15
  • +1 Thanks! I had written a whole script to do this awhile ago. This is much easier! – Joe Sep 04 '13 at 21:57
  • It is worth noting that man -H also works when man is an alias for pinfo, like alias man='pinfo -m', except for pinfo opening an empty page which can be closed immediately. Excellent protip! – Murphy Dec 08 '17 at 09:23
  • 2
    -Hfirefox doesn't work on 18.04: Unable to init server: Could not connect: Connection refused Error: cannot open display: :0 – michid May 24 '19 at 10:07
  • 3
    I'm getting "File not found // Firefox can’t find the file at /tmp/hmanOZ02pL/man.html." Probably because launching new instance of firefox like that passes control to existing instance and immediately exits, which is why temporary file gets deleted even before "real" firefox gets a chance to open it. – ratijas Oct 10 '20 at 12:38
  • 2
    man --html=google-chrome man Failed to move to new namespace: PID namespaces supported, Network namespace supported, but failed: errno = Operation not permitted Trace/breakpoint trap man: couldn't execute any browser from google-chrome – A. Donda Jan 18 '21 at 01:50
  • #!/bin/bash firefox "https://manpages.ubuntu.com/cgi-bin/search.py?q=$1" – MeltingPoint Dec 30 '22 at 06:30
18

man can actually do a lot of this on its own. You just need to install groff (GNU troff text-formatting system) and then you can use the H flag (cause groff to produce HTML output).

sudo apt install groff
man -Hfirefox bash
Pablo Bianchi
  • 15,657
Oli
  • 293,335
8

man2html

To search man pages

I installed the man2html package then navigated to http://localhost/cgi-bin/man/man2html to view the man pages. These pages can be viewed offline, link to other man pages and feature a search function.
Source

To directly open a page (from command line)

I made this script here (it's not short), it just navigates directly to the webpage (from man2html) for a certain manpage. It can open multiple man pages specified as command line arguments. Save the script somewhere and give it execute permissions (chmod +x script.sh). Run it as ~/script.sh (assuming saved in ~ directory) with pages to open as arguments. To open something like init(8), use ~/script "8 init".


dwww

To search man pages

Install the dwww paackage and navigate to http://localhost/dwww/man/1 to search the pages. These pages can be viewed offline, link to other man pages and feature a search function.

To directly open a page (from command line)

I made this script here (it's not short), it just navigates directly to the webpage (from dwww) for a certain manpage. It can open multiple man pages specified as command line arguments. Save the script somewhere and give it execute permissions (chmod +x script.sh). Run it as ~/script.sh page (assuming saved in ~ directory) with pages to open as arguments. To open something like init(8), use ~/script init/8. Without pcregrep, you need to type the /8 all the time, with it, just type the name of the page.

kiri
  • 28,246
  • 16
  • 81
  • 118
2

In response to Dan and ratijas comment : you can force firefox to open in a new process

man -H"firefox -new-instance -P 'default'" ls

I personnally have aliased it as man :

alias man="man -H'firefox -new-instance -P default'" 
  • Interesting. Unfortunately I get a cryptic error message "man: command exited with status 3: (cd /tmp/hmanNNO85n && /usr/lib/man-db/zsoelim) | (cd /tmp/hmanNNO85n && /usr/lib/man-db/manconv -f UTF-8:ISO-8859-1 -t UTF-8//IGNORE) | (cd /tmp/hmanNNO85n && preconv -e UTF-8) | (cd /tmp/hmanNNO85n && tbl) | (cd /tmp/hmanNNO85n && groff -mandoc -Thtml) – Craig Hicks Oct 18 '20 at 20:28
  • The /tmp/blahblah directory is not created. Adding sudo doesn't work either. – Craig Hicks Oct 18 '20 at 20:31
  • 1
    @CraigHicks The status 3 error can be fixed by installing groff – nealmcb Dec 06 '20 at 18:41