Manage Printers via Command Line in OS X

In an enterprise environment you’ll probably be dealing with printers a lot (most likely networked). Here are some command line tools that helped me manage printers at my university:

# List queue name of connected printer(s)

lpstat -p | grep printer | cut -d" " -f2

Note: the cut command allows you to remove all text from the piped output, leaving only the 2nd column which in this case is the name of the printer queue. I use grep to eliminate cutting the wrong lines.

# Delete a specific printer

lpadmin -x <printer_name>

# Delete ALL installed printers

lpstat -p | grep printer | cut -d" " -f2 | xargs -I{} lpadmin -x {}

Note: this command lists all installed printers, “cuts” the output to only show printer names, then sends the names to the xargs command which inputs them into the lpadmin -x command, ultimately removing the printers.

 # Restart CUPS (print) service

sudo launchctl unload /System/Library/LaunchDaemons/org.cups.cupsd.plist
sudo launchctl load /System/Library/LaunchDaemons/org.cups.cupsd.plist

Note: Its good practice to reboot the computer to restart the cups service when configuring printers via command line. If you’re in a situation where you can’t reboot (ex. a user is logged in), you could try restarting the service with the above commands.

# Add network printer(s)

lpadmin -p "office2bw" -v "lpd://" -D "Black & White" -L "Office 2" -P "/Library/Printers/PPDs/Contents/Resources/HP LaserJet P4010_P4510 Series.gz" -E

-p     Printer name (queue name if sharing the printer)
-v     IP address of printer (or DNS name)
-D     Printer description (this is what will be displayed when users choose a printer)
-L     Location of printer
-P     Path to printer driver file
-E     Enable the printer

# Disable printer sharing/discovery for ALL installed printers

lpstat -p | grep printer | cut -d” “ -f2 | xargs -I{} lpadmin -p {} -o printer-is-shared=false

Note: When adding printers via command line, printer sharing is enabled by default. I didn’t know this until after configuring networked printers on our 80 Macs. Instead of undoing everything and starting over, I ran this command. To do this for a single computer, just run lpadmin -p <printer_name> -o printer-is-shared=false.

Sources: Mac Life, Small Business Chron, Apple Support Communities,, TechJournal 318, (printer sharing)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s