Mac OS X Unleashed

Mac OS X Unleashed

By John Ray and William C. Ray

Printing Tools

You already have some printing capability from the Terminal's printing menu options, and built in to the rest of your OS X system. The command line, however, has its own printing facility, allowing you to direct the output of commands to a printer, without having to select that output in the terminal and use the menu options to print. These command line tools are actually fairly sophisticated, although they provide only a minimalist interface to the printing architecture. Print queuing, job-status notification, and print-job logging are all part of the standard Unix lpr printing system.

Sending Jobs to the Printer: lpr

The command to send a job to the printer is lpr. Although there are a number of options to lpr, the most common forms that you will probably use are

lpr <filename>

lpr -P<printer> <filename>

The first example sends <filename> to the system's default printer. The second example sends <filename> to an alternative printer named <printer> . If your system has more than one printer available to it at the command line, the second form might be of use. Note that there is no space between the -P and <printer> . You can send multiple jobs to the printer at once, and they will be queued and printed in sequence.

The command provides no feedback other than a return to your prompt:

[localhost:~] joray% lpr file2

[localhost:~] joray%

The command documentation table for lpr is shown in Table 15.10.

Table 15.10. The Command Documentation Table for lpr

lpr Sends a job to the printer
lpr [-P<printer>] [-#<num>] [-C <class>] [-J <job>] [-T <title>]
[-U <user>] [-i [<numcols>]] [-1234<font>] [-w<num>] [-cdfglnptv]
<file1> <file2> ...
lpr creates a printer job in a spooling area to be printed when facilities become available. A print job consists of a control file and one or more data files, which are copies of the specified files. lpr uses a spooling daemon, lpd, to print the files or to send the files to a remote host if the printer is on a remote host.
-c Assumes that files contain data produced by cifplot(1).
-d Assumes that files contain data from tex (DVI format from Stanford) .
-f Uses a filter that interprets the first character of each line as a standard FORTRAN carriage control character.
-g Assumes that files contain standard plot data as produced by plot routines.
-l Uses a filter that allows control characters to be printed and suppresses page breaks.
-n Assumes that files are assumed to contain data from ditroff (device independent troff).
-p Uses pr(1) to format the files (equivalent to print).
-t Assumes that files contain data from troff(1) (cat phototypesetter commands).
-v Assumes that files contain a raster image for devices such as Benson Varian.
The following options apply to the handling of the print job:
-P <printer> Forces output to a specific printer. Normally the default printer for the site is used, or the value of the environment variable PRINTER is used.
-h Suppresses the printing of a banner page.
-m Sends mail on completion.
-r Removes the file on completion of the spooling or on completion of printing (with the -s option).
-s Uses symbolic links. Usually files are copied to the spool directory. The -s option uses a symbolic link to the data files rather than copying them to the spool directory. Files sent to the printer in this manner should not be modified or removed until they are printed.
The following options apply to copies, the page display, and headers:
-# <num> Prints the number of copies specified by <num> .
-[1234] <font> Specifies a <font> to be mounted on font position i. The daemon constructs a .railmag file referencing the font pathname.
-C <class> Specifies the job classification to be used on the banner page. Replaces the name returned by hostname(1) with <class> .
-J <job> Specifies the job name to be used on the banner page. Normally, the first filename is used.
-T <title> Uses <title> for pr(1) instead of the filename.
-U <user> Specifies <user> as the name to print on the banner page. It is only honored if the real user ID is daemon, and is intended for instances where print filters requeue jobs.
-i [ <numcols> ] Indents the output. If <numcols> is specified, it prints <numcols> of blank spaces before each line. Otherwise, eight characters are printed.
-w <num> Uses <num> as the page width for pr(1).

Checking the Print Queue: lpq

Because lpr provides no feedback other than a return to your prompt, you might sometimes find it useful to check the print queue to check on the status of your print job. The lpq command displays the print queue:

[localhost:~] joray% lpq

     lw360 is ready and printing
     Rank    Owner   Job     File(s)                         Total Size
     active  joray   4       file2                           34 bytes

Surprisingly, it provides quite a bit of information. We see from the lw360 that the machine that hosts the printer knows it as lw360. The remote machine actually could provide arbitrarily complete data for the printer name, so, depending on your setup, the remote administrator could even include location and printer model information here if he chose.

The output displays each print job on one line. In this example, there is only one print job. The line describing the print job includes a print job number and the filename, size, and owner. If there were multiple jobs queued on the printer, however, each would be listed here, along with the job owner, making it very convenient to track down who's hogging all the printer time!

The command documentation table for lpq is shown in Table 15.11.

Table 15.11. The Command Documentation Table for lpq

lpq Displays the queue of print jobs.
lpq [-la] [-P <printer> ] [ <job#> ...] [ <user> ...]
-P <printer> Specifies <printer> as the printer. Otherwise, the site's default printer is used or the value of the PRINTER environment variable.
-l Displays the queue information in long format. Includes the name of the host from which the job originated.
-a Displays the local queues for all printers.
<job#> Displays information on the specified job numbers.
<user> Displays information on all jobs for the specified users.

Removing Printer Jobs: lprm

If you decide that you would like to remove a print job from the queue, use the lprm command. You might find it useful to use in conjunction with lpq.

Here are two examples of using lprm:

[localhost:~] joray% lpq

     lw360 is ready and printing
     Rank    Owner   Job     File(s)                         Total Size
     active  joray   17      file3                           30 bytes
     1st     joray   18      file4                           46 bytes

[localhost:~] joray% lprm 17

     lw360-17: cancelled

[localhost:~] joray% lprm  joray

     lw360-18: cancelled

In the first example, we used lpq to get a print job number, and then used lprm to cancel the specific job number. In the second example, we used the username and cancelled all jobs owned by the specified user. You can cancel jobs only if you are the user they belong to or if you are the super user.

The command documentation table for lprm is shown in Table 15.12.

Table 15.12. The Command Documentation Table for lprm

lprm Removes print jobs from the queue.
lprm [-P <printer> ] [-] [ <job#> ...] [ <user> ...]
-P <printer> Specifies <printer> as the printer. Otherwise, the site's default printer is used or the value of the PRINTER environ ment variable.
- Removes all print jobs in the queue owned by the user invoking the command. If invoked by a super user, removes all print jobs from the queue.
<job#> Removes from the queue the print job specified by <job#> . The <job#> can be determined by using lpq(1).
<user> Removes jobs in the print queue owned by the specified <user> .

Share ThisShare This

Informit Network