Jérôme Belleman
Home  •  Tools  •  Posts  •  Talks  •  Travels  •  Graphics  •  About Me

Adding a Printer from the Command Line

4 Sep 2016

The CUPS web tool does a good job of managing printers, even for someone who dislikes GUIs. But then there's all these cases when some automation is in order.

1 Finding Models and Printers

The lpinfo command helps your find both models and printers. While the -m option lists drivers for known models, the -v option lists available devices, e.g. either directly connected to your machine or visible somewhere on the network. You need to find out about the printer and model as these two bits of information are required by lpadmin to effectively add the printer.

The -m option can work jointly with the --make-and-model option to take an argument and match against model names but I usually like to leave it out and display all possible models known to the current system so I can pipe them all to other commands helping me see the forest of for the trees. You heard me come – I typically leave it to Vi to interactively perform some fuzzy searches:

lpinfo -m | vim -

You'll find that for a given model, several drivers may be available, e.g. PostScript or Gutenprint. I can't really pretend to be able to advise for one or the other. They're probably all worth a shot, taking into account available printer options that will matter to you.

2 Adding the Printer

The lpadmin command can be tricky to operate. In particular, the meaning of options can radically change depending on the order they're supplied on the command line. That's true of -E. For instance:

lpadmin \
    -E \
    -p p3005 \
    -v lpd://p3005.example.com/hp-p3005 \
    -m postscript-hp:0/ppd/hplip/HP/hp-laserjet_p3005-ps.ppd \
    -E

3 Removing the Printer

While we're on the subject of adding printers, removing them is hardly more complicated if you know where you're going. The lpadmin man page does suggest at some point a -r option to remove a printer from a class, but it's really the -x option you want, which deletes the printer:

lpadmin -E -x p3005

As you can see, it's easy to get your inspiration from the command line adding a printer. You can keep -E to use encryption. The -v, -m and -E options become irrelevant. The -p option is replaced with the -x option.

4 References