Using Printing Commands

Using Printing Commands

To remain backward-compatible with older UNIX and Linux printing facilities, CUPS supports many of the old commands for working with printing. Most command-line printing with CUPS can be performed with the lpr command. Word processing applications, such as StarOffice, OpenOffice, and AbiWord, are set up to use this facility for printing.

With the Red Hat Printer configuration window, you can define the filters needed for each printer so that the text can be formatted properly. Options to the lpr command can add filters to properly process the text. Other commands for managing printed documents include lpq (for viewing the contents of print queues), lprm (for removing print jobs from the queue), and lpc (for controlling printers).


Chapter 6 provides examples of how to format and print documents in several different formats, including troff and TeX.

Using lpr to print

With the lpr command, you can print documents to both local and remote printers. Document files can be either added to the end of the lpr command line or directed to the lpr command using a pipe (|). Here is an example of a simple lpr command:

$ lpr

When you just specify a document file with lpr, output is directed to the default printer. As an individual user, you can change the default printer by setting the value of the PRINTER variable. Typically, you would add the PRINTER variable to one of your startup files, such as $HOME/.bashrc. Here is a line to add to your .bashrc file to set your default printer to lp3:

export PRINTER=lp3

To override the default printer, specify a particular printer on the lpr command line. The following example uses the -P option to select a different printer:

$ lpr -P canyonps

The lpr command has a variety of options that enable lpr to interpret and format several different types of documents. These include -# num, where num is replaced by the number of copies to print (from 1 to 100) and -l (which causes a document to be sent in raw mode, presuming that the document has already been formatted).

Listing status with lpc

The lpc command in CUPS has limited features. You can use lpc to list the status of your printers. Here is an example:

$ lpc status
hp:           printer is on device 'parallel' speed -1
                queuing is enabled
                printing is disabled
                no entries
                daemon present
                printer is on device '/dev/null' speed -1
                queuing is enabled
                printing is disabled
                no entries
                daemon present

This output shows two active printers. The first (hp) is connected to your parallel port. The second (deskjet_5550) is a network printer (shown as /dev/null). The hp printer is currently disabled (offline), although the queue is enabled so people can continue to send jobs to the printer.

Removing print jobs with lprm

Users can remove their own print jobs from the queue with the lprm command. Used alone on the command line, lprm removes all the user's print jobs from the default printer. To remove jobs from a specific printer, use the -P option, as follows:

$ lprm -P lp0

To remove all print jobs for the current user, type the following:

$ lprm -

The root user can remove all the print jobs for a specific user by indicating that user on the lprm command line. For example, to remove all print jobs for the user named mike, the root user would type the following:

$ lprm mike

To remove an individual print job from the queue, indicate the job number of that print job on the lprm command line. To find the job number, type the lpq command. Here's what the output of that command may look like:

$ lpq
printer is ready and printing
Rank   Owner                Job Files                Total Size Time
active root                 133 /home/jake/pr1         467
2      root                 197 /home/jake/mydoc     23948

The output shows two printable jobs waiting in the queue. (In this case, they're not printing because the printer is off.) Under the Job column, you can see the job number associated with each document. To remove the first print job, type the following:

# lprm 133

Part IV: Red Hat Linux Network and Server Setup