Third party cookies may be stored when visiting this site. Please see the cookie information.

PenguinTutor YouTube Channel

Linux sysadmin printing reference guide

Introduction

Linux has a number of different methods that can be used to provide printing. This guide is based on the traditional BSD style printing daemons used to manage print queues. These provide a useful way of configuring printers in a server environment and is a requirement for the LPIC 102 exam. The BSD printing system is often better known by the daemon or the main printing command, which are lpd and lpr respectively.

Background

The lpd print system originates from the original BSD printing system which has been implemented on various UNIX operating systems for many years. LPD stands for "Line Printer Daemon", and is the name of the daemon that runs on the system (lpd). It is now still in use as a basic print spooler, although has been replaced by cups for most Desktop systems. It is still particularly useful if you have a server that you would like to be able to print from, but don't want to install cups and all the additional software and filters that would be required for cups printing.

The protocol that the daemon uses is defined in the RFC document 1179 (Line Printer Daemon Protocol). This provides a protocol which allows clients to send jobs to remote printers, and allows for control of the print queues.

There are a number of different implementations of lpd, and the lpd protocol is included in several different printing tools including CUPS and LPRng.

Spooling Daemon (lpd)

The spooling daemon is called lpd. There will be an instance of lpd running on each machine, including the local and remote machine if using remote printing. There will also be an instance of lpd for each printer that is actively printing.

The initial daemon is normally started during system startup. This instance will be running continuously. It listens for connections and is used to manage the queues. Whenever a request comes in (e.g. from the lpr command), the printer daemon accepts the network connection and receives the print data and options.

When lpd identifies an available printer for a queue with a pending job it spawns a child lpd process to handle the printing.

The child lpd daemon applies any appropriate filters as defined in /etc/printcap before sending the data to the printer.

Submitting Prints (lpr)

The lpr command is used to send a print job to the printer. The lpr command communicates with lpd.

Managing Print Jobs (lpq, lpc and lprm)

The three commands lpq, lpc and lprm are used to manage the print queues.

lpq lists the jobs in the print queue
lpc is the control command which can be used to manage the print queue including (stopping the printer, starting the pritner and reordering the jobs on the print queue).
lprm is used to remove one or more jobs from the print queue.

Listing Jobs on the Queue (lpq)

You can use the lpq command to list the jobs on the queue. If run without any parameters it will display jobs on the default queue.

The most common options are:
lpq -a (list jobs on all printers)
lpq -l (provides more information about the jobs – long list format)

Controlling the Printers (lpc)

The line printer control program can be used to control the operation of local printers.

Here are some example commands:

lpc status printername
Show the status of all the named printer. The printername can be replaced with the keyword all to view the status of all local printers.

lpc disable printername
Turns of the print queue. It prevents new printer jobs from entering the print queue. The printername can be replaced with the keyword all to apply to all local printer queues.

lpc enable printername
Allows new jobs to be added to the print queues. The printername can be replaced with the keyword all to apply to all local printer queues.

lpc stop printername
Stops the spooling daemon after the current job has completed. It then disables printing to that printer. The printername can be replaced with the keyword all to view the status of all local printers.

lpc start printername
Enables printing starting a spooling daemon for the printer. The printername can be replaced with the keyword all to view the status of all local printers.

Removing Print Jobs (lprm)

The lprm command is used to remove print jobs from the print queue.

The command can be run without any arguments which will delete the current print request. Normal users can only remove their own print jobs, but the superuser can remove any jobs.

The following are some examples of the lprm command.

lprm -P printqueue jobid
Remove requests from the specified queue.

lprm -
If requested by a user it will remove all jobs from that user. If specified by a superuser it will delete all requests on that print queue.

lprm -a
Delete all your jobs on all printers

lprm -a all
Delete all jobs on all printers from all users (superuser only).

Printer configuration (/etc/printcap)

The file /etc/printcap is used to define the printers for use by lpd.

The following shows the format for the printcap file, with two examples. The first called printer1 (alias name localprinter) is on the first printer port, whereas the second called printer2 (alias name remoteprinter) is on a remote machine.

printer1|localprinter:\ 

        :lp=/dev/lp0:\

        :sd=/var/spool/lpd/printer1:\

        :mx#0:\

        :sh:

 

printer2|remoteprinter:\ 

        :rm=remoteserver:\

        :rp=remoteprinter:\

        :sd=/var/spool/lpd/printer2:\

        :mx#0:\

        :sh:

Common entries in the printcap file are:
lp – Local printer port / device (local printing only)
sd – Spool directory
mx – Maximum buffer size (0 = unlimited)
sh – suppress printing of burst page header
rm – remote server host name (remote printing only)
rp – remote printer queue name (remote printing only)
if – input filter, used to process the input with a program to change the formatting.
af – accounting file
lf – error log file
pl – page length (lines)
pw – page width (characters)

Previous Linux printing using CUPS
Linux printing using CUPS
Next Computer networking overview
Computer networking overview