Section 3.24. Printing a File: lprlpqlprm


[Page 65 (continued)]

3.24. Printing a File: lpr/lpq/lprm

BSD UNIX provided its own print commands, and both sets of commands are supported by Linux. These commands cover the same basic functions of print, check the queue, cancel the job, but have different names and arguments.

To print my file using such a system, use the lpr utility, which works as shown in Figure 3-29.

Figure 3-29. Description of the lpr command.

Utility: lpr -m [-Pprinter] [-#copies] { fileName }*

lpr prints the named files to the printer specified by the -P option. If no printer is specified, the printer in the environment variable $PRINTER is used (for more information about environment variables, refer to Chapter 5, "The Linux Shells"). If no files are specified, standard input is printed instead. By default, one copy of each file is printed, although this may be overridden using the -# option. The -m option causes mail to be sent to you when printing is complete.



[Page 66]

lpr causes a numbered print job to be started for the specified files. You may find the status of a particular job and/or printer by using the lpq utility (Figure 3-30).

Figure 3-30. Description of the lpq command.

Utility: lpq -l [-Pprinter] { job# }* {userId }*

lpq displays the status of jobs on the printer specified by the -P option. If no printer is specified, the printer in the environment variable $PRINTER is used. lpq displays information pertaining to the specified jobs and/or the jobs of the specified users. If no jobs or users are specified, the status of all jobs on the specified printer is displayed. The -l option generates extra information.


If for some reason you wish to cancel a print job, you may do so by using the lprm utility:

Figure 3-31. Description of the lprm command.

Utility: lprm [-Pprinter] [-] { job# }* { username }*

lprm cancels all of the specified jobs on the printer specified by the -P option. If no printer is specified, the printer in the environment variable $PRINTER is used. The - option cancels all of the print jobs started by you. If you are the super-user, then you may cancel all of the jobs owned by a particular user by specifying their username.


You may obtain a list of the printers on your system from your system administrator.

As in our previous example, I started by ordering a printout of "heart.final" from the "lwcs" printer. I then decided to order two more copies, and obtained a printer status. Finally, I changed my mind and canceled the last print job.

$ lpr -Plwcs heart.final      ...order a printout. $ lpq -Plwcs glass     ...look at the printer status. lwcs is ready and printing Rank    Owner  Job  Files        Total Size active  glass  731  heart.final  213 bytes $ lpr -#2 -Plwcs heart.final       ...order two more copies. $ lpq -Plwcs glass     ...look at the printer status again. lwcs is ready and printing Rank    Owner  Job  Files        Total Size active  glass  731  heart.final  213 bytes active  glass  732  heart.final  426 bytes $ lprm -Plwcs 732      ...remove the last job. centaur: dfA732vanguard dequeued centaur: cfA732vanguard.utdallas.edu dequeued $ _ 



[Page 67]

In the next example, I used the keyboard to compose a quick message for the printer, and requested mail notification of job completion:

$ lpr -m -Plwcs     ...print from standard input. Hi there, This is a test of the print facility. - Graham ^D      ...end of input. $                        ...wait a little. $ mail                   ...read my mail. Mail version 8.1 6/6/93.  Type ? for help. >N 1 daemon@utdallas.edu Sat Jan 31 18:04 15/502  printer job & 1                      ...read the first mail message. From: daemon@utdallas.edu To: glass@utdallas.edu Subject: printer job Date: Tue, 31 Jan 2005 18:04:32 -0600 Your printer job (stdin) Completed successfully & q                      ...quit out of mail. $ _ 





Linux for Programmers and Users
Linux for Programmers and Users
ISBN: 0131857487
EAN: 2147483647
Year: 2007
Pages: 339

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net