Home Links About

View local man pages in the browser

One of the best parts of using Linux or any other Unix-like OS is the documentation that is included. Most people don’t seem to read it though, but I found that a lot of times answers to questions are better found in the man pages than on stackoverflow or anywhere else on the web.

It can however be cumbersome to read longer man pages in the terminal; the formatting is not particular nice and non-fixed width font is arguably better for reading long texts. Luckily, it is easily possible to convert a man page to a format like HTML or DVI or PostScript.

The quickest way is to use a command like man -t ls > /tmp/ls.ps. This will generate a PostScript version of the man page, which can be viewed by your usual PDF viewer.

Viewing man pages in the browser

Personally, I prefer HTML for reading man pages, since I have a browser open always anyway. To convert a man page to HTML, you can call man like man -l -Thtml /usr/share/man/man1/ls.1.bz2.

The problem here is that we need to provide the path to the man page to view, since this command is a bit different than man -t. Luckily we can call man -w ls, which prints the path to the man page of ls. Putting this all together, we can create a small shell function to view any man page in the browser:

hman() {
	path=$(man -w "$@")
	man -l -Thtml "$path" > /tmp/man.html
	firefox /tmp/man.html
}

By putting this in your .bashrc, you can easily run something like: hman ls