FreeKB - How to print from the Terminal in Linux
How to print from the Terminal in Linux

Home > Search > How-to

Listing available printers

The LPSTAT command with the -p option can be used to display the list of available printers

[root@server1 ]# lpstat -p
printer HP-Photosmart-C6200-seriesCMD:PCL is idle. enabled since Mon 01 Jan 2016 00:00:01 AM CST
    ready to print


Similarly, the LPC command will show the status of the available printers.

[root@server1 `]# lpc status
	printer is on device 'hp' speed -1
	queuing is enabled
	printing is enabled
	no entries
	daemon present



There are a few different commands that can be used to sent print jobs to the printer.

  • PR (print)
  • LP (Line print)
  • LPR (Line print request)
  • LPD (Line print daemon)


The PR command is intended to format a file for printing. For example, let's say the file named unformatted-file has the following content.

Hello World
How are you today?


The PR command has a number of options to format the file. -n numbers the list, and -h adds a header named "Greetings".

[root@server1 ]# pr -n -h "Greetings" unformatted-file > formatted-file


Both the LP and LPR command can be used to print a file. Without any additional options, these two commans are identical. The default printer in the /etc/cups/cupsd.conf file will be used.

[root@server1 ]# lp formatted-file
[root@server1 ]# lpr formatted-file


The LP and LPR commands have quite a few options. As an example, if you have more than one printer or more than one print queue, the lp -d or lpr -P commands can be used to specify a printer or queue. 

[root@server1 ]# lp -d HP-Laserjet-4000 formatted-file
[root@server1 ]# lpr -P HP-Laserjet-4000 formatted-file


For a complete list of options, view the info or man page.

[root@server1 ]# man lp
[root@server1 ]# info lpr


It is noteworthy that the LPD command can also be used. LPD is a legacy command used with older systems.


Print queue

After sending the print job to the printer, the LPQ command can be used to view the print job in the queue. LPQ without any options shows every print queue.

[root@server1 ]# lpq
HP-Photosmart-C6200-seriesCMD:PCL is ready
Rank     Owner  Job  File(s)          Total Size
active   root    1   formatted-file   1024 bytes
active   root    3   Example Job Name 1024 bytes

HP-Lasterjet-4000 is ready
Rank     Owner  Job  File(s)          Total Size
active   root    2   formatted-file   1024 bytes


The -P option can be used to specify a certain printer or queue.

[root@server1 ]# lpq -P HP-Lasterjet-4000
HP-Lasterjet-4000 is ready
Rank     Owner  Job  File(s)          Total Size
active   root    2   formated-file    1024 bytes


Cancelling a print job

If some problem occurs, and the print job doesn't print, we can cancel the print jobs in the queue. The lpq cancel command with no options cancels the current print job on the default printer. 

[root@server1 ]# lpq cancel


The lpq cancel -a command without any additional options cancels every print job on every printer being managed by CUPS in the network.

[root@server1 ]# lpq cancel -a


The lpq cancel -a command followed by the printer name will cancel every print job on a certain printer.

[root@server1 ]# lpq cancel -a printer_name


Likewise, the LPRM command can be used to remove a print job. In this example, the print with Job ID 3 is removed.

[root@server1 ]# lprm 3


The - character removes every print job in the queue.

[root@server1 ]# lprm -


Viewing print history

The /var/spool/cups directory will contain a list of files. Some of these files will contain copies of what was printed. For example, the print-test can be viewed.

[root@server1 ]# cat /var/spool/cups/d000019-0011 
2016-11-22 15:35               formatted-file           Page 1

Hello World.
How are you today?



Add a Comment

We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.

Please enter in the box below so that we can be sure you are a human.