1. Home
  2. Computing & Technology
  3. Linux

Introduction to Linux

From Machtelt Garrels, for About.com

8.1.1. Command line printing

8.1.1.1. Getting the file to the printer

Printing from within an application is very easy, selecting the Print option from the menu.

From the command line, use the lp or lpr command.

lp file(s)

lpr file(s)

These commands can read from a pipe, so you can print the output of commands using

command | lp

There are many options available to tune the page layout, the number of copies, the printer that you want to print to if you have more than one available, paper size, one-side or double-sided printing if your printer supports this feature, margins and so on. Read the man pages for a complete overview.

8.1.1.2. Status of your print jobs

Once the file is accepted in the print queue, an identification number for the print job is assigned:


   

davy:~> lp /etc/profile
request id is blob-253 (1 file(s))

To view (query) the print queue, use the lpq or lpstat command. When entered without arguments, it displays the contents of the default print queue.


   

davy:~> lpq
blob is ready and printing
Rank Owner Job File(s) Total Size
active davy 253 profile 1024 bytes
davy:~> lpstat
blob-253 davy 1024 Tue 25 Jul 2006 10:20_01 AM CEST

8.1.1.3. Status of your printer

Which is the default printer on a system that has access to multiple printers?

lpstat -d


   

davy:~> lpstat -d
system default destination: blob

What is the status of my printer(s)?

lpstat -p


   

davy:~> lpstat -p
printer blob now printing blob-253. enabled since Jan 01 18:01

8.1.1.4. Removing jobs from the print queue

If you don't like what you see from the status commands, use lprm or cancel to delete jobs.


   

davy:~> lprm 253

In the graphical environment, you may see a popup window telling you that the job has been canceled.

In larger environments, lpc may be used to control multiple printers. See the Info or man pages on each command.

There are many GUI print tools used as a front-end to lp , and most graphical applications have a print function that uses lp . See the built-in Help functions and program specific documentation for more.


       Why are there two commands for every task related to printing?
        

Printing on UNIX and alikes has a long history. There used to be two rather different approaches: the BSD-style printing and the SystemV-style printing. For compatibility, Linux with CUPS supports the commands from both styles. Also note that lp does not behave exactly like lpr , lpq has somewhat different options than lpstat and lprm is almost, but not quite, like cancel . Which one you use is not important, just pick the commands that you are comfortable with, or that you may know from previous experiences with UNIX-like systems.

* License

* Introduction to Linux Index

Explore Linux

More from About.com

  1. Home
  2. Computing & Technology
  3. Linux
  4. Linux Documentation
  5. Introduction to Linux
  6. Introduction to Linux - Printing files

©2008 About.com, a part of The New York Times Company.

All rights reserved.