Printing With Unix

A UNIX system can have a number of printers. You may have a little HP Deskjet connected directly to your workstation. Your workstation may be networked to a UNIX host which has a heavy-duty line-printer and a large laser printer.

In UNIX, you give your printers names. You could call your little HP Deskjet printer 'jet'. The host's large line printer could be called 'bigboy'. The laser could be called 'lassy'.

When you configure UNIX on your machine, you specify which printer is going to be your default printer. It does not have to be the one that is connected directly to your machine. Your machine may not have one. When you do not specify any printer, UNIX uses your default printer. Otherwise when you give a print command you specify the printer to be used as follows:

When you use the lp command to print something, it does not actually do the printing itself. It merely creates a print request which it puts on UNIX's print request queue. A print daemon deep within UNIX then handles the print requests in turn from the queue and performs the actual printing task as shown below.

This means that a lot of users on different terminals can each submit print requests to the same printer at the same time and they get put on the queue to be carried out in order without getting mixed up.

When you issue a print request such as lp file1, UNIX confirms your request by giving it a job number which it displays as follows.

This allows you to identify the job later if anything goes wrong and you have to try to find out what has happened to it.

The lp command prints straight from the original file file1. So if after having placed the print request, you delete file1 before the print daemon has got around to printing it, the daemon will not be able to find it. To avoid this, you can tell the lp command to copy it to a print spool file first before putting the print request on the queue as follows.

The Berkeley command lpr spools print automatically. To stop it doing so type lpr -s file1. Useful for big files as spooling takes extra time and disk space which you may not have. Berkeley also has the facility to print-then-delete a file, lpr -r file1. So to print-then-delete a large file you type lpr -s -r file1.

BERKELEY BSD lpr only:
-s suppress the automatic spooling of your file before printing
-r automatically erase your actual file after having printed it

System V Printer Status Report

You can get the status of all the printers that are accessible to you as follows:

lpstat -a all
bigboy accepting requests since 13:43:50 Thu 25 Apr 1991
jet accepting requests since 10:20:13 Fri 12 May 1993
lassy accepting requests since 09:15:22 Mon 19 Jun 1994

The report tells you when each printer was installed and put on-line. For an individual printer, you type its name:

lpstat -a jet
jet accepting requests since 10:20:13 Fri 12 May 1993

If you type lpstat without any arguments you get the current status of each print request on the print queue as follows:

System V - To Cancel a Print Request

To cancel this print request by removing it from the print queue and stopping any more of it being printed if it is already being printed, type:

cancel lassy-2620
request "lassy-2620" cancelled

If you want to cancel all the pending jobs on a given printer, type:

cancel lassy

NOTE: If the printer has an internal buffer, a lot of the file may still be in the buffer when you cancel the request. The printer may therefore carry on printing for 20 pages or more unless you clear or reset the printer's internal buffer.

Berkeley Printer Status Report

The equivalent printer status command and its associated report are:

lpq -a
bigboy:
Rank Owner Job Files Total Size
1st eustace 7 file1 4615 bytes
lassy:
Rank Owner Job Files Total Size
2nd eustace 23 file2 250327 bytes
jet:
Rank Owner Job Files Total Size
3rd sharon 12 email1 438 bytes

To get the current status of only those printers which are currently active or have request pending in their queues, type lpq on its own.

To cancel a print request you refer to it by its job number, in this case 23 as follows:

lprm 23

Berkeley BSD responds with some utter gibberish that only a UNIX guru can understand.

Print Formatting Command

UNIX provides the pr command to format plain text files into titled pages as they are being passed for printing. The syntax and switches for the pr command are as follows:

pr can also print the contents of two or more files side-by-side in columns:


This page's parent within this Web Site. About this Web Site. Its home page. Email its Author.