The following were removed from Chapter 3: “Learning About Commands”.
man’s Database of Commands
Occasionally you'll try to use
man to find out information about a command and
man reports that there is no page for that command. Before giving up, try again with the
-u option (or
--update), which forces
man to rebuild the database of commands and man pages it uses.
$ man ls No manual entry for ls $ man -u ls LS(1) User Commands LS(1) NAME ls - list directory contents SYNOPSIS ls [OPTION]... [FILE]... [Listing condensed due to length]
man -u is often a good first step if you think things aren't quite as they should be with the man database.
Print man Pages
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
$ man -t ls | lpr -P hp_laserjet
You'll learn about the pipe symbol (
|) in Chapter 4, "Building Blocks," and
lpr in Chapter 6, "Printing and Managing Print Jobs."
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
You'll learn about the
&& symbols in Chapter 4.
If you want to make a printed library of man pages covering your favorite commands, or if you want that library in PDF format, 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.