Of course! lpadmin is the primary command-line tool for managing printers on systems that use the Common UNIX Printing System (CUPS), which is the standard on Linux, macOS, and other UNIX-like operating systems.
It allows you to perform administrative tasks like adding, modifying, and removing printer queues. Here’s a comprehensive guide on how to manage printers with lpadmin.
Important: You will almost always need sudo to run lpadmin commands, as they modify system-wide settings.
1. The Basics: Core Concepts
Printer Queue:lpadmin doesn't configure the physical printer directly. It creates and manages a printer queue on your computer. This queue has a name (e.g., Office_LaserJet), holds print jobs, and knows how to send them to the physical device.
Device URI: This is the address of the physical printer. It tells CUPS where to send the data (e.g., over the network or a USB cable).
PPD File (PostScript Printer Description): This is the driver. It's a text file that tells CUPS about the printer's capabilities (paper sizes, duplexing, resolution, etc.).
2. Listing Existing Printers and Drivers
Before you add a printer, you need to know what's available.
List currently configured printer queues:
bash
lpstat -p -d
-p shows printer queues and their status.
-d shows which printer is the system default.
Find the Device URI of connected printers:
This command lists all available backends and discovered printers. It's the best way to find the correct URI for your device.
bash
lpinfo -v
For a Network Printer: Look for lines like socket://192.168.1.100 or ipp://printer.example.com/ipp/print.
For a USB Printer: Look for lines like usb://HP/LaserJet%20Pro%20M404dn?serial=....
Find available drivers (PPDs):
This command lists all the drivers CUPS knows about. It's a very long list, so use grep to find your model.
bash
lpinfo -m | grep -i "laserjet"
3. Adding a New Printer
This is the most common use of lpadmin. The general syntax is:
-p <printer_name>: Specifies the name for the new printer queue (e.g., Accounting_HP, Warehouse_Zebra). Use a simple name without spaces.
-E: Crucial! This enables the printer and tells it to start accepting jobs. If you forget this, the printer will be added but remain disabled.
-v <device_uri>: The "address" of the printer you found using lpinfo -v.
-m <model/driver>: The driver file to use. There are a few ways to specify this:
Recommended (Modern Printers): Use the keyword everywhere. This uses the driverless IPP Everywhere™ standard, which most modern network printers support.
Specific Driver: Use one of the model names you found with lpinfo -m.
PPD File: If you downloaded a PPD file manually, provide the full path to it.
Example 1: Adding a modern network printer using IPP Everywhere
bash
# The printer's IP address is 192.168.1.55
sudo lpadmin -p OfficeJet_Pro -E -v ipp://192.168.1.55/ipp/print -m everywhere
Example 2: Adding an older HP network printer with a specific driver
# First, find the URI
# lpinfo -v | grep usb
# --> usb://Canon/iP2700%20series?serial=AB1234
# Then, find the driver
# lpinfo -m | grep -i "iP2700"
# --> gutenprint.5.3://bjc-PIXMA-iP2700/expert
# Now, add the printer
sudo lpadmin -p Canon_iP2700 -E -v "usb://Canon/iP2700%20series?serial=AB1234" -m "gutenprint.5.3://bjc-PIXMA-iP2700/expert"
4. Modifying an Existing Printer
You use the same -p <printer_name> flag to select the printer you want to modify.
Set a Location and Description:
This is very helpful for users to identify the right printer.
bash
sudo lpadmin -p OfficeJet_Pro -D "Main Office Color Printer" -L "2nd Floor, West Wing"
-D "Description": A human-readable description.
-L "Location": The physical location of the printer.
Change the Driver or URI:
If you move a printer to a new IP address or find a better driver, you can update it.
bash
# Change the IP address
sudo lpadmin -p OfficeJet_Pro -v ipp://192.168.1.57/ipp/print
# Change the driver
sudo lpadmin -p OfficeJet_Pro -m /path/to/new/driver.ppd
5. Setting Printer Options and Defaults
You can set default options for a printer, like always printing in duplex or using a specific paper tray.
Find available options for a printer:
bash
lpoptions -p OfficeJet_Pro -l
This command is essential! It will list all the keywords for options like PageSize, Duplex, InputSlot, etc.
Set default options:
Use the -o flag. You can use it multiple times.
bash
# Set default to A4 paper and double-sided printing
sudo lpadmin -p OfficeJet_Pro -o PageSize=A4 -o Duplex=DuplexNoTumble
6. Deleting a Printer
Use the -x flag to delete a printer queue. This will also cancel any jobs waiting in that queue.
bash
sudo lpadmin -x OfficeJet_Pro
7. Managing the System Default Printer
The default printer is the one used by commands like lp when no specific printer is named.
bash
# Set 'LaserJet4050' as the system-wide default printer
sudo lpadmin -d LaserJet4050
8. Controlling Printer State (Enabling/Disabling)
While you can use lpadmin, the modern tools for this are cupsenable and cupsdisable.
Disable a printer (stops printing, but jobs can still be queued):
bash
sudo cupsdisable LaserJet4050
Enable a printer:
bash
sudo cupsenable LaserJet4050
Reject new jobs (existing jobs will print, but no new ones are accepted):
bash
sudo cupsreject LaserJet4050
Accept new jobs again:
bash
sudo cupsaccept LaserJet4050
Practical Workflow: Summary Cheatsheet
Here is a quick summary of the most common tasks.
bash
# 1. List available devices and drivers
lpinfo -v
lpinfo -m
# 2. Add a new network printer
sudo lpadmin -p MyPrinter -E -v socket://192.168.1.100 -m everywhere
# 3. Add descriptive info
sudo lpadmin -p MyPrinter -D "My Awesome Printer" -L "My Desk"
# 4. List configured printers
lpstat -p -d
# 5. Set it as the default printer
sudo lpadmin -d MyPrinter
# 6. List its available options
lpoptions -p MyPrinter -l
# 7. Set some default options (e.g., Duplex)
sudo lpadmin -p MyPrinter -o Duplex=DuplexNoTumble
# 8. Remove the printer when no longer needed
sudo lpadmin -x MyPrinter
For the complete list of all possible options, you can always consult the manual page: man lpadmin.