Thursday, January 20, 2011

Create PDF files of man pages in Ubuntu

One of the most important feature of linux is its internal online help called man pages which gives a detailed description of any command, its options and syntax. A help on a command can be obtained by simply typing man followed by the command name. For example,
man ls
will give details on the syntax and options of ls command.

If such a detailed entry is needed to be sent to someone over the net, then you may want to convert it into a pdf file. Here's a simple trick that could do it using two simple tools - man and ps2pdf.

man with -t option gives output in postscript format which is well suited for printing.
ps2pdf does the function of printing to a pdf file. So that's the simple trick here. We're going to pipe the output of man -t to ps2pdf and assign it a filename. And we're done.

For example,

man -t ls | ps2pdf - ~/ls_manpage.pdf

The above example creates a pdf file named ls_manpage.pdf in the user's home directory whose contents is that of the man ls command. 

No comments:

Post a Comment