How to Use the `lpadmin` Command (with examples)
The lpadmin
command is a powerful tool used for managing printers and classes in the Common UNIX Printing System (CUPS). It is highly versatile, allowing administrators to configure, add, remove, and delete printers and printer classes with ease. Understanding the lpadmin
command is essential for effective printer management on UNIX-based systems. The guide provides specific use cases to illustrate the functionality of lpadmin
.
Use case 1: Set the Default Printer
Code:
lpadmin -d printer
Motivation:
Setting a default printer is crucial for organizations or individuals who frequently print documents and want to streamline their workflow. By designating a particular printer as the default, all print jobs are sent to this printer unless specified otherwise, saving time and reducing errors in selecting the wrong printer.
Explanation:
lpadmin
: The command being used to administer printer configurations.-d
: This option specifies that you want to set a default printer.printer
: Replace this with the actual printer name or ID that you wish to set as the default.
Example Output:
There is no direct output in the terminal when setting the default printer, but you can verify the change with the command lpstat -d
. The output might look like:
system default destination: printer
Use case 2: Delete a Specific Printer or Class
Code:
lpadmin -x printer|class
Motivation:
As printers or classes become obsolete or unnecessary, it is important to remove them to maintain an organized and functional printing environment. Deleting a printer can reduce clutter in the printer selection menus and prevent accidental sending of documents to the wrong, or non-existent, printer.
Explanation:
lpadmin
: The command being used for printer and class management.-x
: This option is used to delete a specified printer or class.printer|class
: The name of the printer or class that you want to remove. Replaceprinter
orclass
with the actual name.
Example Output:
Successful execution will not output a confirmation to the terminal. However, attempting to list the removed printer or class using a command like lpstat -p
will no longer show the deleted item.
Use case 3: Add a Printer to a Class
Code:
lpadmin -p printer -c class
Motivation:
Grouping printers into classes can increase efficiency by distributing print jobs among several printers. If you have multiple printers that can handle similar types of jobs, adding them to a class facilitates load balancing and provides redundancy, ensuring documents can be printed even if one printer is unavailable.
Explanation:
lpadmin
: The command being used to modify printer setups.-p
: Specifies the printer you are targeting to add.printer
: The name of the printer being added to the class.-c
: Signifies the printer class.class
: Replace this with the name of the class you want to include the printer in.
Example Output:
No direct output will be displayed upon adding a printer to a class. To confirm the addition, use lpstat -c class
to view the members of the class. The output could look like:
class members: printer1 printer2
Use case 4: Remove a Printer from a Class
Code:
lpadmin -p printer -r class
Motivation:
Removing a printer from a class is sometimes necessary for maintenance purposes or when the printer is reallocated for a different task. Ensuring that classes only contain relevant and functional printers helps maintain optimal operation of the printing network.
Explanation:
lpadmin
: As before, this command is used to handle printer configurations.-p
: Identifies which printer is being adjusted.printer
: The specific printer name that you intend to remove from a class.-r
: Used to remove the printer from the specified class.class
: The target class from which you want to remove the printer.
Example Output:
There is no explicit output when removing a printer from a class. To confirm removal, you can use lpstat -c class
, which should show the class members excluding the removed printer.
Conclusion:
The lpadmin
command is an essential utility for systems that rely on CUPS for managing their printing environments. By mastering the above use cases, administrators can efficiently manage printer configurations, leading to a more organized and functional system. Whether setting default printers, cleaning up old configurations, or managing printer classes, lpadmin
provides the tools necessary for streamlined operations.