Home > Articles

  • Print
  • + Share This
This chapter is from the book

This chapter is from the book

Print Man Pages

man -t

As easy as it is to view man pages using a terminal program, sometimes it's necessary to print out a man page for easier reading and cogitation. Printing a man page isn't a one-step process, however, and the commands that round out this particular section are actually using principles that will be covered extensively later. But if you want to print out a man page, this is the way to do it. Just have faith that you'll understand what these commands mean more fully after reading upcoming chapters.

Let's say you have a printer that you have identified with the name hp_laserjet connected to your system. You want to print a man page about the ls command directly to that printer, so use the -t option (or --troff) and then pipe the output to the lpr command, identifying your printer with the -P option.

$ man -t ls | lpr -P hp_laserjet

In just a moment or two, depending upon the speed of your computer and your printer, hp_laserjet should begin spitting out the man pages for ls. Maybe you don't want to actually print the pages, however. Maybe just creating PDFs of the man page for the ls command would be enough. Once again, the commands to do so might seem a bit arcane now, but they will be far more comprehensible very soon.

Again, you use the -t option, but this time you send the output to a PostScript file named for the ls command. If that process completes successfully, you convert the PostScript file to a PDF using the ps2pdf command, and then after that finishes correctly, you delete the original PostScript file because it's no longer needed.

$ man -t ls > ls.ps && ps2pdf ls.ps && rm ls.ps

If you want to make a printed library of man pages covering your favorite commands, or if you want that library in PDF format (which can then be printed to hard copies, if necessary), now you know how to do it. For something so simple, man is powerful and flexible, which makes it even more useful than it already is.

  • + Share This
  • 🔖 Save To Your Account