Create an HTML version of man pages

There is a program designed for the purpose of creating an HTML version of a manual page (man page). This program is called man2html. However, man2html does not create a table of contents in the resulting HTML, which would be very useful for long man pages. But we can actually accomplish that with the man utility itself, believe it or not!

The man utility gives us the ability to view a man page in a browser, with the man page formatted into HTML (with table of contents). This is done using the following command:

man -Hbrowser page

where “browser” is the browser you wish to use, for example “firefox” or “google-chrome” (these need to be in your PATH), and where “page” is the man page you wish to read, for example “bash” or “emacs”.

Unfortunately, the HTML file created for this purpose is a temporary file which is deleted! So if you close the tab or window of the browser, or even refresh the page, you will get an error telling you the HTML file cannot be found anymore! To get around this, we trick the man utility into using the cat utility as the browser. We then let cat redirect its output of the HTML file to a permanent file, like so:

man -Hcat bash > bash.html

After that, we can view the file in a browser:

google-chrome bash.html

Enjoy!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: