Common Unix Printing System

Printing with Linux

What is CUPS?


CUPS (Common Unix Printing System) is a printer spooler and various utilities that allow you to manage local and remote printers on your network. CUPS was originally designed to work with the IPP (Internet Printing Protocol), however, it has now become a replacement for the older BSD and System V printing utilities. The CUPS process runs as a daemon "cupsd". It is here that the print queues are managed. On most systems the cups process is started by default:




john@john-desktop:~$ initctl status cups
cups start/running, process 628
john@john-desktop:~$ ps -ef | grep cupsd
root       628     1  0 19:39 ?        00:00:00 /usr/sbin/cupsd -F

The above shows the cups process and the "cupsd" cups daemon running on an Ubuntu desktop installation.

The management and configuration of your printers can be handled by a web interface which can be found by specifying:
http://localhost:631


CUPS


The above shows that I have two printers defined to my system. The active connection is a shared printer on my network, the "unplugged" entry indicates that the device is no longer locally attached via a USB connection.

From this web interface I can manage my printers, print queues, jobs. Simply click on the tabs "Administration", "Classes", "Jobs" and "Printers" to access the relevant areas.


CUPS Overview


The first time you send a print to a printer using CUPS, a special queue is created for the handling of your print. It is this queue that keeps track of the current status of your print job. Each time you create a print, CUPS creates a job that contains the queue you are printing to along with the name of the document you are printing. Once a job has completed successfully its output is purged from the print queue. CUPS then will look for any other jobs that are awaiting to print. Accessing the web interface allows you to monitor the progress of your jobs and printers. While your jobs are printing, you can cancel the output. You can also move the output to another queue (printer).

The easiest way to learn more about the CUPS printing system is to access the web interface and look at the various menu options. Here you will find a wealth of information explaining all the functionality that you can use within CUPS. If you haven't access to this web interface, you can find a full overview at the official CUPS web site


Printing from the command line


As we mentioned previously CUPS can handle the Berkeley "lpr" print commands and also the System V "lp" commands. It is always useful to have a basic knowledge of some of these commands as this will allow you to print directly from scripts, manage your queues and printers without the need of the web interface.

CUPS can understand many different file types including text, Postscript, PDF and images. This allows you to print from other applications such as Libre Office, Gimp, evince pdf viewer without any difficulty.


lp and lpr - print command


Print a file Basic Syntax: lp filename

Display Print Queue basic Syntax: lpq

The easiest way to print a file from the command line is to use either the "lp" or "lpr" command. In its simplest form we issue "lp filename".



john@john-desktop:~$ lp test.txt
request id is Eastman-Kodak-Company-KODAK-HERO-3.1-AiO-76 (1 file(s))
john@john-desktop:~$ lpq
Eastman-Kodak-Company-KODAK-HERO-3.1-AiO is ready and printing
Rank    Owner   Job     File(s)                         Total Size
active  (null)  76      untitled                        1024 bytes

The above example shows the basic use of the "lp" command for sending a print and the "lpq" command to display our job queue. If you don't specify a printer, the default printer is used.


Display Available Printers


Display available printers syntax: lpstat -p

The "lpstat" command is used to display available printers on your system. The "-p" option specifies to display a list of printers. The "-d" option displays your default printer:



john@john-desktop:~$ lpstat -p -d
printer Eastman-Kodak-Company-KODAK-HERO-3.1-AiO is idle.  enabled since Sat 16 Mar 2013 22:04:14 GMT
	Ready to print.
printer Eastman-Kodak-Company-KODAK-HERO-3.1-AiO-2 disabled since Mon 10 Sep 2012 21:07:28 BST -
	Unplugged or turned off
system default destination: Eastman-Kodak-Company-KODAK-HERO-3.1-AiO


Print to a Specific Printer


lp -d printer filename When using the "-d" option with the "lp" command you can specify your printer.

lpr -P printer filename

When using the "lpr" command we must use the "-P" parameter to specify a printer.


Setting your Default Printer


As we saw earlier, the command "lpstat -p -d" displayed available printers along with the "system default destination". If we wanted to change this we could use the web interface, or simply issue the "lpoptions -d printer" command.


 
john@john-desktop:~$ lpoptions -d "Eastman-Kodak-Company-KODAK-HERO-3.1-AiO-2"
auth-info-required=none copies=1 device-uri=usb://Eastman%20Kodak%20Company/KODAK%20HERO%203.1%20AiO?serial=03H7871&interface=1 finishings=3 job-hold-until=no-hold job-priority=50 job-sheets=none,none marker-change-time=1345023581 marker-colors=black,magenta marker-levels=5,55 marker-names=black,colour number-up=1 printer-commands=Clean,PrintSelfTestPage,PrintAlignmentPage,ReportLevels printer-info='Eastman Kodak Company KODAK HERO 3.1 AiO' printer-is-accepting-jobs=true printer-is-shared=true printer-location=john-desktop printer-make-and-model='KODAK HERO 3.1 AiO' printer-state=5 printer-state-change-time=1347307648 printer-state-reasons=paused printer-type=8425484 printer-uri-supported=ipp://localhost:631/printers/Eastman-Kodak-Company-KODAK-HERO-3.1-AiO-2
john@john-desktop:~$ lpstat -p -d
printer Eastman-Kodak-Company-KODAK-HERO-3.1-AiO is idle.  enabled since Sat 16 Mar 2013 22:04:14 GMT
	Ready to print.
printer Eastman-Kodak-Company-KODAK-HERO-3.1-AiO-2 disabled since Mon 10 Sep 2012 21:07:28 BST -
	Unplugged or turned off
system default destination: Eastman-Kodak-Company-KODAK-HERO-3.1-AiO-2

Now we can see that our new default destination has been set to: Eastman-Kodak-Company-KODAK-HERO-3.1-AiO-2

To switch back to our original printer we can issue the command again: "lpoptions -d "Eastman-Kodak-Company-KODAK-HERO-3.1-AiO"



john@john-desktop:~$ lpstat -d
system default destination: Eastman-Kodak-Company-KODAK-HERO-3.1-AiO

By issuing "lpstat -d" without any other parameters displays only your default destination.


Printing multiple copies


Quite often you will want to print more than one copy of a file or report to a printer. To achieve this we can use one of the following commands:

lp -n no_of_copies filename

lpr -#no_of_copies filename


Cancelling a print job


To cancel a job we can issue one of the following commands followed by the "job id" cancel job_id

lprm job_id

The "job_id" is normally displayed after the "lp" command has been issued. However, you can view this again by issuing the "lpq" command or the "lpstat" command.


CUPS - Configuration Files


All the configuration files for CUPS can be found under the following location: "/etc/cups"

/etc/cups/cupsd.conf
This is the main configuration file that is used to configure "cupsd". Various information and configurations can be found here. we can define who can manipulate printers and queues, what ports to listen on etc....

/etc/cups/printers.conf
This file is generated automatically by "cupsd". It will contain changes made to printers, additions etc..

/var/spool/cups
This area is used by "cupsd" to spool data awaiting print.