Tuesday, September 13, 2011

Linux man pages to pdf

Anybody who has ever handled a unix type machine, at some point or other has used the command

man command-name

to  check the manual of the said command. Ever wanted to convert the man page to pdf so that you could search through it or even print it for that matter?
There is an easy solution for this. Run the command

man -t command-name | ps2pdf - > filename.pdf

And your man page of the command get converted to a pdf file.
Eg:


man -t gnuplot | ps2pdf - > gnuplot_man.pdf


You can even write a small shell-script for this. Fire up your favorite text editor
and paste the following code

#!/bin/bash
Cmd="$1"
man -t "$Cmd" | ps2pdf - > "$Code"_man.pdf


Save it as man2pdf and make it executable.

chmod +x man2pdf


Now all you have to do is run the command like this:

./man2pdf command-name


You could even move it to your local bin directory if you want.

Try it. :)

No comments:

Post a Comment