Indiana University
University Information Technology Services
  
What are archived documents?
Login>>
Login

Login is for authorized groups (e.g., UITS, OVPIT, and TCC) that need access to specialized Knowledge Base documents. Otherwise, simply use the Knowledge Base without logging in.

Close

In Unix, how do I print files and list or remove print jobs?

The various implementations of Unix handle printing tasks in different ways. Most systems, however, understand either the BSD or System V commands, or in some cases, both. The UITS central servers at Indiana University, in particular, support both varieties. AIX, the operating system on the Research Database Complex (RDC), has its own print commands, but it also supports BSD and System V commands. This document will not cover AIX print commands.

The following sections explain how to do a number of printing tasks. Be sure to pay attention to what kind of printing commands (BSD or System V) your system uses. If your system uses both flavors of printing commands, experiment to see which commands work the best for you.

At IU, the laser printers in the Student Technology Centers and the Residential Technology Centers, as well as printers in offices, cannot print using normal Unix print commands. Instead, try the ansiprt command. For more, see In Unix, how do I print a file to my local printer?

Using BSD commands

Printing

To print a file from a BSD-compatible system, use the lpr command. The general syntax for BSD is: lpr [switches] filename lpr [switches]

Replace [switches] with optional command line switches. Switches allow you to specify certain options, such as a particular printer or output format. Replace filename with the name of the file you want to print.

For example, to print a file named myfile.txt to the default printer in a system that uses the BSD-compatible commands, at the Unix prompt, enter: lpr myfile.txt

For information on designating a default printer, see In Unix, how do I designate my default printer?

To send a print job to a printer other than the default printer, you need to specify its name. With BSD commands, do this using the  -P  flag. For example, to print myfile.txt to a printer named ps99, enter: lpr -Pps99 myfile.txt

Note: Do not include a space between the  -P  and the printer's name.

BSD also allows you to suppress the printing of a banner page with the  -h  option; to do this, enter: lpr -Pps99 -h myfile.txt

You can also use the lpr command in a pipeline to print the output from other Unix commands. For example, to print out a long listing of the contents of the current directory with BSD, enter: ls -la | lpr -Pps99 -h

For BSD, to see a listing of available printers and their names, read the file /etc/printcap. Public printers will often be tagged with their names.

Note: As configured on most systems, the lpr command takes text (straight ASCII) or PostScript input without requiring any switches. If you are printing a PostScript file, make sure that the printer you're using is PostScript compatible before you issue the command. On some BSD-compatible operating systems, lpr can also print .dvi files if you specify the  -d  switch, but this works inconsistently and UITS doesn't recommend it.

Listing print jobs

With BSD printing commands, use lpq to list the jobs (files waiting to be printed) for a particular printer. To find what jobs are queued on the default printer, at the Unix prompt, enter: lpq

To check what jobs are queued to print on a printer named ps99, you would enter: lpq -Pps99

The listing returned by lpq reports the rank, owner, job number, filename, and file size of each print job in the queue or actually printing.

Removing print jobs

With BSD, the lprm command lets you cancel the printing of a file. To remove a print job, first use the lpq command to find the job number of the print request you want to cancel. Then use the lprm command to kill the job by specifying the job number. For example, if you want to kill job number 11042 on printer ps99, enter: lprm -Pps99 11042

Note: Unless you have system administration privileges, you can remove only print jobs that you have submitted, not jobs submitted by other users.

Using System V commands

Printing

To print in System V, use the lp command. The syntax is as follows: lp [switches] filename lp [switches] Replace [switches] with optional command line switches. Switches allow you to specify certain options, such as a particular printer or output format. Replace filename with the name of the file you want to print.

For example, to print a file named myfile.txt to the default printer in a system that uses System V commands, enter: lp myfile.txt

For information on designating a default printer, see In Unix, how do I designate my default printer?

To send a print job to a printer other than the default printer, you need to specify its name. In System V, use the  -d  flag to do this. For example, to print myfile.txt to a printer named ps99, enter: lp -d ps99 myfile.txt

You can also use the lp command in a pipeline to print the output from other Unix commands. For example, to print out a long listing of the contents of the current directory with System V, enter: ls -la | lp -dps99

To see a list of printers available for the lp command, enter: lpstat -a

Note: As configured on most systems, the lp command takes text (straight ASCII) or PostScript input without requiring any switches. If you are printing a PostScript file, make sure that the printer you're using is PostScript compatible before you issue the command.

Listing print jobs

With System V, use the lpstat command to list the jobs for a particular printer. Using lpstat prints the status of all your print requests made by lp to the default or designated printer. To see the status of print jobs you have sent to the queue of the default printer that are still waiting, enter: lpstat

To check what jobs are pending for a particular printer, use the lpstat -P command. For example, to view the queue for printer ps99, enter: lpstat -Pps99

Removing print jobs

With System V, use the cancel command to stop the printing of a file. To cancel a job, even if it's already printing, use the lpstat command to find the job number. Then use the cancel command to kill that job. For example, if you want to kill the job ps99-4, enter: cancel ps99-4

Note: Unless you have system administration privileges, you can remove only print jobs that you have submitted, not jobs submitted by other users.

At Indiana University, for personal or departmental Linux or Unix systems support, see At IU, how do I get support for Linux or Unix?

This is document adzr in domain all.
Last modified on June 30, 2009.

I need help with a computing problem

  • Fill out this form to submit your issue to the UITS Support Center.
  • Please note that you must be affiliated with Indiana University to receive support.
  • All fields are required.



Please provide your IU email address. If you currently have a problem receiving email at your IU account, enter an alternate email address.

I have a comment for the Knowledge Base

  • Fill out this form to submit your comment to the IU Knowledge Base.
  • If you are affiliated with Indiana University and need help with a computing problem, please use the I need help with a computing problem section above, or contact your campus Support Center.