It is very difficult for me to perform printing, because the printer dialogue is full of hundreds of automatically added printers, so I can't find the one I want to use, see screenshot below.

Image of printer dialogue showing a very long scroll bar

The printers stem from my work network, where apparently lots of people (including students, I guess) are "sharing" their home printers, which my laptop then picks up automatically. (coincidentally I sometimes disable the avahi-daemon at work, simply because it is using a large amount of CPU).

When I go to http://localhost:631/printers/, it says there are 131 printers, and they are all of Make and Model 'Local Raw Printer'. With two exceptions: 1 is a network printer at work that I manually configured. Another is a network printer at my parents', which was also automatically added and which I am on the same network as right now. But the rest are just garbage that I would really like to avoid. Tips on how to do that would be appreciated.

I will not be going back to my work place for a bit of time though, so for now, I would just like these printers (that would be the 129/130 automatically added printers) to be removed. Is there a way to do that? I guess I could do it by clicking through in the cups web interface, but for 129 printers, that is a bit much. So I am looking for a single command or tips on how to achieve it with a script of sorts.

  • 4
    see /etc/cups/printers.conf. stop cups and then remove the printers from the file. – Rinzwind May 30 '19 at 19:05
  • 3
    It's not a duplicate because I am asking how to remove already installed printers, while that other question is about preventing their installation. Also, it's a question which has a hot mess of outdated answers which don't work. I know this because I've seen it before and tried some of it. – jonaslb May 30 '19 at 19:56
  • 2
    Understood, retracted :) – NGRhodes May 30 '19 at 20:08
  • 1
    What bugs me is that when I press in the printers administration window GUI refresh button, they do not disappear. They system should attempt to contact them and remove any network printer that is not responding. Anybody aware of any bug/feature request regarding this? – Hans Deragon Feb 1 '20 at 0:09

Using this command: lpstat -a we can see the installed printers and identify the name of the desired printer to keep, we can use the grep command also to filter the results like so: lpstat -a | grep <probable_name_of_printer>.

Then this little script can help:

  1. Run this command to check that the desired printer is not listed:

    lpstat -a | cut -d" " -f1 | sed -E '/<NAME_OF_PRINTER>/d' | grep <NAME_OF_PRINTER>
    • This should return nothing as it does the following:

      • lpstat -a: list installed printers
      • cut -d" " -f1: return only the names of the printers
      • sed -E '/<NAME_OF_PRINTER>/d': remove the name of the printer to keep from the output of the previous commands
      • grep <NAME_OF_PRINTER>: make sure the desired printer is not on the list
  2. If the above checks out; then run this command to remove every other printer that you don't need:

    sudo bash -c 'for i in $(lpstat -a | cut -d" " -f1 | sed -E '/<NAME_OF_PRINTER>/d'); do lpadmin -x "$i"; done'
  • This looks promising. I think there might be an issue though (with the listing command so presumably also the last command). lpstat -a results in <printer_name> not accepting request since <some date> -\n reason unknown (with reason unknown on a new line!). So using your listing command I get a lot of "printers" named ` reason` (there's an indentation). – jonaslb May 30 '19 at 20:42
  • Please which part of the steps are you having issues and add any results to your question so I can follow! What does the command lpstat -a give you? – George Udosen May 30 '19 at 20:46
  • 1
    It worked fine, but I added another sed command in the "pipe chain": sed -E /reason/d to be rid of the extra lines. – jonaslb May 30 '19 at 20:56
  • Great work and glad it worked! – George Udosen May 30 '19 at 20:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.