Red Hat Linux 7 Unleashed

Red Hat Linux 7 Unleashed

By William Ball

Linux Printing Commands

Of course, you don't have to use the printtool command to set up your printer. You can edit /etc/printcap directly, but you should know what you're doing and understand printcap's format. This file, an ASCII database of your system's local and networked printers, describes the capabilities of each printer in detail. For full details, see the printcap man page for commands and the termcap man page for the file's layout.

In fact, you can have multiple entries for each printer, which is helpful if you want to print different size papers, print color or black-and-white documents by switching cartridges, or change printer trays.

Old versions of Red Hat Linux used the 4.3BSD line-printer spooling system. This system has a number of features and associated programs to support background printing, multiple local and networked printers, and control of the printers and queued documents.

The main files used in the older printer spooling system were as follows:


These files provided the basic features needed to initiate and control print jobs from the command line. See Table 19.3 for a selected list of additional Linux commands you may find helpful when printing.

Red Hat Linux now uses Patrick Powell's LPRng print spooler software, which is descended from the 4.3BSD release but rewritten from the ground up. LPRng offers a host of benefits and features over the previous printer spooling software, such as being distributed under the GNU GPL, backward compatibility, security, diagnostics, and multiple printers on a single queue. In addition to the previously listed commands, LPRng also uses


These additional files are used for site-specific settings, to check or fix LPRng's installation, to set permissions for users, and to report on a printer's status.

When you first boot Linux, the shell script, lpd (under /etc/rc.d/init.d/) starts lpd, the printer daemon. This program, a printer server, runs in the background and waits for print requests. When a request is detected on the print queue, the server connects to the designated printer and passes the document stream through the proper printer filter.

Print requests are started with the lpr command. For example, the following command line will print your document to a file in the /var/spool/lpd/lp directory using the printer named lp:

   # lpr -Plp myfile.txt

Other print-spooling commands can help track your request. If you're printing a large document or a number of smaller files, you can see a list of print jobs running by using the lpq command. For example, to print a number of files at once to the default printer, use this:

   # lpr *

Follow that command with this:

   # lpq

This outputs the following:

Printer: lp@thinkpad
 Queue: 1 printable job
 Server: pid 3631 active
 Unspooler: pid 3632 active
 Status: processing '', size 1309, format 'f', IF filter
'filter'at 17:40:52.610
 Rank   Owner/ID                  Class Job Files                 Size Time
active root@thinkpad+630            A   630 adsl,amd,anacron,apm 14542 17:40:51

This shows quite a bit of information, but the important item to note is the job number (630 in this example). If you want to stop the preceding print job, use the lprm command, followed by the job number, as in the following:

   # lprm 630
Printer lp@thinkpad:
  checking perms 'root@thinkpad+630'
  dequeued 'root@thinkpad+630'

This shows that lprm has removed the spool files and stopped the job. To disable or enable a printer and its spooling queue, rearrange the order of any print jobs, or find out the status of printers, you can use lpc from the command line or interactively, but you must be logged in as root or as a superuser (through the su command).

LPRng's lpc command is very comprehensive and offers much more control over system and network printing than the legacy lpc command. This command may be used to activate or abort the print server, disable or enable print queuing, hold or release print jobs, and even move print jobs to a different printer! Start lpc on the command line like this:

   # lpc

To view the built-in help on command keywords and syntax, type help or press ? like this:

lpc> help

After you press Enter, you'll see several pages of help text for lpc's 30 different commands. A more abbreviated command is LPRng's lpstat. Use the command like this:

   # lpstat
Printer: lp@thinkpad
 Queue: no printable jobs in queue
 Status: subserver pid 3632 exit status 'JABORT'at 17:43:05.111

If you have print jobs waiting, you'll see a list of jobs, along with information similar to that returned by lprm.

LPRng is documented through its commands' man pages and documentation under the /usr/share/doc/LPRng-3.6.22 directory. You'll find the latest version and documentation (including an excellent HOWTO document) at

Table 19.3. Selected Printing Commands

Command Description
cancel LPRng utility to cancel print service
checkpc Verifies and fixes LPRng print system files
lpc Controls program for local and remote printers
lpd LPRng print server daemon
lpf General printer filter
lpr Sends print jobs to printer queue
lprm Controls print queue
lpstat Displays specified print service status
mpage Prints multiple pages of text per sheet
nprint NetWare print client
pbm2ppa Converts bitmap to HP PPA format
pbmto10x Converts bitmap to Gemini printer graphic
pbmtoepson Converts bitmap to Epson printer graphic
pbmtoppa Converts bitmap to HP PPA format
pbmtoptx Converts bitmap to Printronix printer graphic
pnm2ppa Converts any map to HP PPA format
pqlist Lists NetWare print queue
pqrm Removes jobs from NetWare print queue
pqstat Lists jobs in NetWare print queue
pr Formats text files for printing
printmail Formats mail messages for printing
pserver NetWare print server
sliceprint Formats documents with long lines
smbclient Essential command used by smbprint for printing
smbprint Shell script for printing to shared printers
testprns Printer name check utility for Samba
tunelp Parallel-port hardware utility

+ Share This