Free Hosting Online for WorkStations

< Previous | Contents | Next >

lpr – Print Files (Berkeley Style)

The lpr program can be used to send files to the printer. It may also be used in pipelines, as it accepts standard input. For example, to print the results of our multicolumn directory listing above, we could do this:



[me@linuxbox ~]$ ls /usr/bin | pr -3 | lpr

[me@linuxbox ~]$ ls /usr/bin | pr -3 | lpr


and the report would be sent to the system’s default printer. To send the file to a different printer, the -P option can be used like this:


lpr -P printer_name

lpr -P printer_name


where printer_name is the name of the desired printer. To see a list of printers known to the system:



[me@linuxbox ~]$ lpstat -a

[me@linuxbox ~]$ lpstat -a


Tip: Many Linux distributions allow you to define a “printer” that outputs files in PDF (Portable Document Format), rather than printing on the physical printer. This is very handy for experimenting with printing commands. Check your printer con- figuration program to see if it supports this configuration. On some distributions, you may need to install additional packages (such as cups-pdf) to enable this ca- pability.


Here are some of the common options for lpr:


Table 22-2: Common lpr Options


Option Description

Option Description

-# number Set number of copies to number.


-p Print each page with a shaded header with the date, time, job name, and page number. This so-called “pretty print” option can be used when printing text files.


-P printer Specify the name of the printer used for output. If no printer is specified, the system’s default printer is used.


-r Delete files after printing. This would be useful for programs that produce temporary printer-output files.



Top OS Cloud Computing at OnWorks: