- Nov 21, 2005
Printing man Pages
Unix man pages are plain-text files written using a special formatting syntax (see man mdoc for a tutorial). The raw files are not suitable for printing because they contain text that the man command uses to produce boldface, underlining, and other text formatting, but in many cases you can translate the man page into HTML or PostScript.
Note that the printing techniques described here work for many, but not all, man pages, simply because some converters may not be able to handle certain formatting commands (the man pages may have been written at different times). However, you'll always be able to see the text on the screen—on the printed page you may get truncated text or missing paragraph breaks.
See Chapter 6, "Editing and Printing Files," for more on printing from the command line.
To print a man page to a PostScript printer:
- man -t command | lp For example, if you want a printed man page for the date command: man -t date | lp You are using the -t option of the man command to produce PostScript output and piping that into the lp command. If you're not using a PostScript printer, you will probably get a nicely formatted result because Mac OS X includes open-source Unix software that helps non-PostScript printers print PostScript. (If you are curious, see the Gimp-Print Web site, http://gimp-print.sourceforge.net, for more about this software.)
Besides converting man pages to PostScript, you can also convert many of them to PDF or HTML (or TIFF, or JPEG, or many other formats). This will allow you to view pages in the Preview application or a Web browser and print them to any printer.
To convert a man page to PDF:
- man -t command > command .ps This creates a PostScript file from the man page. It is important that you include the .ps at the end of the output filename.
- open command.ps This opens the PostScript file. By default, the file opens in the Preview application, which automagically converts it to PDF for display.
- Choose File > Save in the Preview application. You get the standard Mac save-file dialog, where you choose the name and location for saving the file.
- Choose PDF from the Format menu in the dialog. Notice that you have the choice of several formats.
- Click Save. You're done.
To convert a man page to HTML:
- Find the raw man page. Use the -w option to the man command—for example: man -w bash bash is just the name of the command for which we want the man page. Even though bash is your shell, it is still just another command.
- You can now try viewing the HTML page with your default browser, even from the command line: open bash.html