Beginners Guide to Printing in Linux

Printing Files

You can use the lp command, the lpstat command and the cancel command to submit print requests to a destination, to display the status of all user print requests, and to cancel print requests.

Using the lp Command

The lp command queues text files for printing. From the command line, you can print ASCII text or PostScript™ technology files. Do not use this method to print data files, such as binary files or files created in programs, such as FrameMaker.

The syntax for the lp command is:

$ lp options filenames

The table below describes the options that you can use with the lp command.

Option Description
-d destination Specifies the desired printer. The -d destination option is not necessary if printing to the default printer.
-o nobanner Specifies that the banner page is not to be printed.
-n number Prints a specified number of file copies.
-m Sends a mail message to you after a job is complete.

To print the dante file located in your home directory on the default printer, perform the lp command without options.

$ lp /export/home/user1/dante
request id is printerA-4 (1 file(s)) $

Using the lpstat Command

The lpstat command displays the status of the printer queue. The syntax for the lpstat command is:

$ lpstat -options printer

The table below describes the options for the lpstat command.

Option Description
-p Displays the status of all printers
-o Displays the status of all output requests
-d Displays the system default printer
-t Displays complete status information for all printers
-s Displays a status summary for all printers
-a Displays which printers are accepting requests

To display the status of all print requests, perform the lpstat command with the -o option.

$ lpstat -o
printerA-5 user1 391 Mar 11 16:30 on printerA
printerB-3 user2 551 Mar 11 16:45 filtered
$

The table below describes the information in the status response of the lpstat command.

Status Definition
Request-ID Name of the printer and job number
User-ID Name of the user accessing the printer
File Size Output size in bytes
Date/Time Current date and time
Status Status of the print request

To display requests in the queue for printerB, perform the lpstat command followed by the printer name.

$ lpstat printerB
printerB-3 user2 551 Mar 11 16:45 on printerB $

To determine the status of all configured printers, perform the lpstat command with the -t option.

$ lpstat -t
scheduler is running
system default destination: printerA
system for printerB: host2
system for _default: host1 (as printer printerA)
system for printerA: host1
printerB accepting requests since Mar 7 09:43 2020
_default accepting requests since Mar 8 08:20 2020
printerA accepting requests since Mar 8 08:20 2020
printer printerB is idle. enabled since Mar 7 09:43 2002. available.
printer _default is idle. enabled since Mar 8 08:20 2002. available.
printer printerA is idle. enabled since Mar 8 08:20 2002. available.
$

To determine which printers are configured on the system, perform the lpstat command with the -s option.

$ lpstat -s
scheduler is running
system default destination: printerA
system for printerB: host2
system for _default: host1 (as printer printerA)
system for printerA: host1

To display which printers are accepting requests, perform the lpstat command with the -a option.

$ lpstat -a
printerB accepting requests since Mar 7 09:43 2002
_default accepting requests since Mar 8 08:20 2002
printerA accepting requests since Mar 8 08:20 2002
$

Using the cancel Command

The cancel command enables you to cancel previously sent print requests, using the lp command. You can use the lpstat command to identify the printer associated with your print request. The syntax for the lp cancel command is:

$ cancel Request-ID
or
$ cancel -u username
$ lpstat printerB
printerB-3 user3 630 Mar 11 16:45
printerB-4 user3 631 Mar 11 16:45
printerB-5 user3 632 Mar 11 16:47

To cancel the print request, perform the cancel command followed by the Request-ID argument.

$ cancel printerB-5
printerB-5: cancelled
$

To remove all requests made by user3, perform the cancel -u username command.

$ cancel -u user3
printerB-3: cancelled
printerB-4: cancelled
$

As the root user, you can cancel all print requests owned by all users. If you are not a root user, you can only remove your own print jobs.