Printing Files

To print a text file (a file which you can edit), you use the lp command where you specify the printer and the name of the file. The default printer is whatever printer is in the lab you’re currently using. To print the Java source file called myprog1.java you type the following:

hostname{~}% lp myprog1.java

Printer Names

An option -d and the name of the printer specify the different printers. The names of the printers are the following:

brki167-lp1 laser printer in Breakiron 167 (specifically for Jr/Sr CS Majors).
brki164-lp1 laser printer in Breakiron 164.
dana213-lp1 laser printer in Dana 213.

For example, to print a letter to Mom on the laser printer in Breakiron 164, you would type the following:

hostname{~}% lp –dbrki164-lp1 letter.mom

The command lp only prints what's in the file. It does not include the date or even the filename! One uses the pr command to add the date, time, name of file and page number at the top of each page. Normally one uses the following for printing programs and output which is to be handed in for a class.

hostname{~}% pr myprog1.cc | lp

In the above, pr formats the C++ file myprog1.cc and pipes (read about pipes in Section 2.8.6 on “Pipes and Filters.”) the formatted output to lp to be printed. You may choose the alternate two columns output format for your submission. You would type the following to submit your homework:

hostname{~}% a2ps –Pdana213-lp1 myprog1.cc

Checking a Printer Queue

Since several people may request to print a file on a printer at the same time, your request is placed in a queue. You can display the contents of a printer's queue with the lpstat command where you specify the printer name by using the –o (lowercase letter o) option. To check the queue of the laser printer in room 164 Breakiron, you would type.

hostname{~}% lpstat –o brki164-lp1

Removing Requests from a Printer Queue

At times you find you may need to remove a request from a printer's queue. Perhaps, you discover that you printed the wrong file and don’t want to waste paper. First, perform a lpstat command and notice the job ID of the print request to be removed. Then issue a cancel command specifying the job ID. Below we remove job ID brki164-lp1-20 from the line printer queue.

hostname{~}% cancel brki164-lp1-20

On rare occasions, a print request will hang the printer. If there are print requests in the queue and the printer has not printed for many minutes, perhaps the first (top) job in the queue is problematic. After checking that the printer is turned on, has paper, not jammed, is on-line, etc., then remove the first job from the queue with cancel. You can remove only your own printer requests. If the first job is not yours then you need to find that person or report the problem to the System Administrator.