Learning the Printing Commands


Learning the Printing Commands

After you have set up the print queue for a printer on your Red Hat Linux system, you can type commands in a terminal window to print and check the status of the print queue. The following sections provide an overview of the basic printing commands. You can use either System V or BSd UNIX print commands. Table 4-1 summarizes the two sets of print commands. In addition to these commands, you can use lpadmin to manage the printer queues and lpoptions to set default options for a print queue.

Table 4-1: System V and BSD Print Commands

Task

System V Command

BSD Command

Submit a print job

lp

lpr

Cancel a print job

cancel

lprm

Check status of a print job

lpstat

lpq

Printing a File

You can use the lp or lpr command to print a file. For example, to print the file rfc1789.txt, you can type the following lp command in a terminal window:

lp rfc1789.txt

This lp command then queues the rfc1789.txt file for printing on the default printer. The default printer is identified by the <DefaultPrinter queuename> entry in the CUPS configuration file /etc/cups/cupsd.conf (where queuename is the name of the print queue).

Insider Insight 

When you use the lp command to print a file, lp sends that file along with information about the print job to the cupsd print scheduler that stores this information in a control file and a data file in the /var/spool/cups directory. The cupsd scheduler then processes the files according to the file extension (such as .txt or .ps) and sends them to the printer using its backend interfaces. Thanks to various configuration files, the cupsd scheduler knows what to do to make sure that the file—be it a text file or an image file—gets printed properly.

You can embellish the simple lp command with some options. If you have many different print queues defined, you can specify the destination of the print job with the -d option. For example, to send a print job to the Hewlett-Packard LaserJet 5000 printer named Rm5N28hplj5000 you would type the following command (later, in the “Understanding the CUPS Configuration Files” section, you’ll see that the print queue name appears in the /etc/cups/printers.conf file),

lp -d Rm5N28hplj5000  rfc1789.txt

If you mistakenly print a large file and want to stop the print job before you waste too much paper, you can use the lpstat or lpq command to look at the current print jobs and then cancel the large print job. Here is a typical output from the lpstat command after I typed the lp command to print a file on the queue named Office-ES600:

lpstat
Office-ES600-2          root             15360   Wed 15 Jan 2003 04:25:48 PM EST

The first field of the output shows the name of the queue with a job number appended to it (that number identifies the print job). You need that job number to cancel the print job.

When I typed lpq for the same print job, here is the output I get:

lpq
Office-ES600 is ready and printing
Rank    Owner   Job     File(s)                         Total Size
active  root    2       testprint.ps                    15360 bytes

The lpq command also shows the job number. It also shows the name of the file that I am printing (testprint.ps).

To remove a job from the print queue, use the cancel or lprm command. For example, to remove print job 2, type the following command:

cancel 2

You can get the same result with the following lprm command:

lprm 2
Insider Insight 

If you are in a hurry and want to cancel all print jobs you have submitted so far, use cancel or lprm with -a as the argument, as follows:

cancel -a

Specifying Print Options

You can use the -o option with the lp and lpr commands to specify print job options such as paper size, whether to print in landscape orientation, and whether to print a banner page at the start and the end of a print job. For example, suppose that you want to print a file on a A4-size paper instead of U.S. letter-size paper that happens to be the default. You can specify this in the print command, as follows:

lp -o media=A4 letter.pdf

That part—-o media=A4—specifies the value of the standard option named media that can set the size, type, and source of the output media (paper or transpartency). If you also want a standard banner page at the start of the print job, you can add the job-sheets option and specify the type of banner you want:

lp -o media=A4 -o job-sheets=standard letter.pdf

There is an extensive set of standard options, but some of them would work only if your printer supports that option. You can specify these options the -o option of the lp command.

Use the lpoptions command to see what options a printer supports. Suppose that you have a print queue named hpdj8 for a HP Deskjet printer. You can query the options it accepts with the following command:

lpoptions -p hpdj8 -l
ColorModel/Output Mode: CMYK2 *CMYK Gray
Resolution/Output Resolution: *300dpi 600x300dpi 600dpi
Duplex/Double-Sided Printing: *None DuplexNoTumble DuplexTumble
PageSize/Media Size: *Letter Legal Executive Tabloid A3 A4 A5 B5 EnvISOB5 Env10
EnvC5 EnvDL EnvMonarch
InputSlot/Media Source: *Tray Manual Envelope Auto
MediaType/Media Type: *Plain Bond Special Transparency Glossy
PageRegion/PageRegion: Letter Legal Executive Tabloid A3 A4 A5 B5 EnvISOB5 Env10
 EnvC5 EnvDL EnvMonarch
Option1/Duplexer: True *False

The first field on each line is the name of the option. The text between the forward slash (/) and the colon (:) is the description of that option. The rest of the lines show the possible values you can specify for that option. The default value is marked with an asterisk (*).

Controlling the Print Queue

To see the names of printers connected to your system, use the lpc status command. On my system, the lpc status command shows the following:

lpc status
Office-ES600:
        printer is on device 'parallel' speed -1
        queuing is enabled
        printing is enabled
        no entries
        daemon present

Notice that queuing and printing are both enabled for this printer. The last line tells you that the cupsd daemon is running and available to handle print jobs.

You can use the accept and reject commands to enable or disable queuing for a print queue. For example, to stop queuing further print jobs for the Office-ES600 printer, I would type:

reject Office-ES600

This command disables queuing jobs for this printer. If anyone tries to send a print job using the lp command, the user receives an error message like this:

lp: unable to print file: server-error-not-accepting-jobs

If you want to allow queuing of print jobs, but want to start or stop the printing, use the enable and disable commands. When you disable printing, users can submit print jobs, but nothing gets printed until you enable printing again. For example, here is the command I use to disable printing on the Office-ES600 printer:

disable Office-ES600
Insider Insight 

If you are trying to print, but nothing seems to be coming out of the printer, check the printer status with the lpc status command and make sure that the daemon is present and that both queuing and printing are enabled. To allow the queuing of print jobs, use the accept command and to start printing, use the enable command.