How to use the command lpadmin (with examples)

How to use the command lpadmin (with examples)

The lpadmin command is used to configure CUPS printers and classes. CUPS stands for Common UNIX Printing System, and it is a modular printing system for Unix-like computer operating systems.

Use case 1: Set the default printer

Code:

lpadmin -d printer

Motivation:

Setting the default printer can be useful when you have multiple printers connected to your system and you want to specify which one should be used as the default for printing.

Explanation:

  • -d: This argument is used to set the default printer.
  • printer: This is the name of the printer that you want to set as the default.

Example output:

Setting the default printer to “Printer1”:

Default destination changed to printer1

Use case 2: Delete a specific printer or class

Code:

lpadmin -x printer|class

Motivation:

Deleting a specific printer or class can be necessary when you no longer need it or when you want to reconfigure your printer setup.

Explanation:

  • -x: This argument is used to delete a printer or class.
  • printer|class: This is the name of the printer or class that you want to delete. You can either specify a single printer or class, or use a wildcard character * to delete multiple printers or classes.

Example output:

Deleting a printer named “Printer1”:

Printer "Printer1" deleted

Deleting all classes:

Class "Class1" deleted
Class "Class2" deleted
Class "Class3" deleted

Use case 3: Add a printer to a class

Code:

lpadmin -p printer -c class

Motivation:

Adding a printer to a class can help you manage your printer setup more efficiently by grouping similar printers together.

Explanation:

  • -p: This argument is used to specify the printer that you want to add to a class.
  • printer: This is the name of the printer that you want to add.
  • -c: This argument is used to specify the class to which you want to add the printer.
  • class: This is the name of the class to which you want to add the printer.

Example output:

Adding a printer named “Printer2” to the class “Class1”:

Printer "Printer2" successfully added to class "Class1"

Use case 4: Remove a printer from a class

Code:

lpadmin -p printer -r class

Motivation:

Removing a printer from a class can be necessary when you want to reorganize your printer setup or when you no longer want a printer to be associated with a specific class.

Explanation:

  • -p: This argument is used to specify the printer that you want to remove from a class.
  • printer: This is the name of the printer that you want to remove.
  • -r: This argument is used to remove the printer from a class.
  • class: This is the name of the class from which you want to remove the printer.

Example output:

Removing a printer named “Printer2” from the class “Class1”:

Printer "Printer2" successfully removed from class "Class1"

Conclusion:

The lpadmin command provides a set of useful functions for configuring CUPS printers and classes. It allows you to set the default printer, delete specific printers or classes, add printers to classes, and remove printers from classes. By using these commands, you can efficiently manage your printer setup and customize your printing experience.

Related Posts

How to use the command age-keygen (with examples)

How to use the command age-keygen (with examples)

The age-keygen command is used to generate key pairs for encryption and decryption in the age encryption tool.

Read More
How to use the command `doxygen` (with examples)

How to use the command `doxygen` (with examples)

Doxygen is a documentation system that is used to generate documentation for various programming languages.

Read More
MongoDB Shell Command Examples (with examples)

MongoDB Shell Command Examples (with examples)

MongoDB Shell is a powerful command-line interface tool provided by MongoDB to interact with MongoDB databases.

Read More