45.2. Introduction to Printing on Unix
Unix used a print spooler to allow many users to share a single printer long before Windows came along. A user can make a printing request at any time, even if the printer is currently busy. Requests are queued and processed in order as the printer becomes available.
Unix permits multiple printers to be connected to the same system. If there is more than one printer, one printer is set up as the default printer, and print jobs are sent there if no printer is specified.
45.2.1. lpr-Style Printing Commands
$ lpr notes
The lpq command tells you the status of your print jobs by showing you the print queue for a given printer.
$ lpq lp is ready and printing Rank Owner Job Files Total Size active fred 876 notes 7122 bytes 1st alice 877 standard input 28372 bytes 2nd john 878 afile bfile ... 985733 bytes
The word active in the Rank column shows the job that's currently printing. If your job does not appear at all on the listing, it means your job has finished printing or has been completely written into the printer's input buffer (or perhaps that you accidentally printed it to a different queue). If a job is not active, it's still in the queue.
$ lprm 877 dfA877host dequeued cfA877host dequeued
The command lpc status (Section 45.3) can be used to determine which printers are connected to your system and their names. If there is more than one printer, you can then use the -P option with lpr, lpq and lprm to specify a printer destination other than the default. For instance, if a laser printer is configured as laserp, you can enter:
$ lpr -Plaserp myfile
If you'll be using a certain printer often, put its name in the PRINTER environment variable (Section 45.4).
If you're using an older system that has only lp (see below), or if you'd like a fancier lpr that supports all sorts of handy features, take a peek at LPRng (available at http://www.lprng.com). It supports everything standard lpr does and more, including a GUI for detailed configuration.
45.2.2. lp-Style Printing Commands
The System V-style print system, which Solaris uses by default, has the lp command to queue a print job. (Solaris also optionally includes lpr-style printing commands, if you install the BSD compatibility package.) When you use lp, it spools the file for printing and returns the request id of your print job. The request id can later be used to cancel the print job, if you decide to do so.
$ lp notes request-id is lp-2354 (1 file)
The lpstat command can be used to check on the status of your print jobs. Like lpq, it will tell whether your job is in the queue or fully sent to the printer. Unlike lpq, it shows you only your own jobs by default:
$ lpstat lp-2354 14519 fred on lp
The message on lp indicates that the job is currently printing. If your job does not appear at all on the listing, it means your job has either finished printing or has been completely written into the printer's input buffer (or you accidentally printed it to a different queue). If the job is listed, but the on lp message does not appear, the job is still in the queue. You can see the status of all jobs in the queue with the -u option. You can cancel a job with the cancel command.
$ lpstat -u lp-2354 14519 fred on lp lp-2355 21321 alice lp-2356 9065 john $ cancel lp-2356 lp-2356: cancelled
The lpstat command can be used to determine what printers are connected to your system and their names. If there is more than one printer, you can then use the -d option with lp to specify a printer destination other than the default. For instance, if a laser printer is configured as laserp, then you can enter:
$ lp -dlaserp myfile
If you'll be using a certain printer often, put its name in the LPDEST environment variable (Section 45.4).
-- DD, TOR, and JP
Copyright © 2003 O'Reilly & Associates. All rights reserved.