Полезная информация

UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 43.1 Introduction to Printing Chapter 43
Printing
Next: 43.3 Printer Control with lpc
 

43.2 Introduction to Printing on UNIX

Personal computers often have dedicated printers. A dedicated printer is connected to your machine and only you can use it. You can send it only one print job at a time and have to wait until the printing finishes before you can go back to work.

UNIX uses a print spooler to allow many users to share a single printer. 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 automatically sent there.

43.2.1 System V Printing Commands

In System V, the lp command is used to queue a print job. (Berkeley systems' printer commands are explained below.) 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. The lpstat command will tell whether your job is in the queue.

$ 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 finished printing. If the job is listed, but the on lp message does not appear, then 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

43.2.2 Berkeley Printing Commands

BSD UNIX uses the lpr command to queue a print job. When you use lpr, it spools the file for printing.

$ lpr notes

Unlike System V lp, the lpr command doesn't print a request id. If you need to kill the job, use lpq first. The lpq command tells you the status of your print jobs.

$ 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. If a job is not active, it's still in the queue.

You can remove a job with the lprm command. (First, run lpq to get the job number.)

$ lprm 877
dfA877host dequeued
cfA877host dequeued

The command lpc status (43.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 to specify a printer destination other than the default. For instance, if a laser printer is configured as laserp, then you can enter:

$ lpr -Plaserp myfile

The -P option also works with lpq and lprm. If you'll be using a certain printer often, put its name in the PRINTER environment variable (43.4).

- DD, TOR, JP


Previous: 43.1 Introduction to Printing UNIX Power ToolsNext: 43.3 Printer Control with lpc
43.1 Introduction to Printing Book Index43.3 Printer Control with lpc

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System