Linux cupsd Command with Practical Examples

LinuxLinuxBeginner
Practice Now

Introduction

In this lab, you will learn how to manage printers and configure printer settings using the CUPS (Common Unix Printing System) printing system and the cupsd command in a Linux environment. You will start by understanding the CUPS printing system, including checking the status of the CUPS service and exploring the CUPS web interface. Then, you will learn how to manage printers using the cupsd command, such as listing available printers and adding new ones. Finally, you will explore how to configure printer settings, such as setting the default printer and adjusting printer options. This lab provides practical examples and hands-on experience with the CUPS printing system, which is a crucial skill for Linux system administration.

Linux Commands Cheat Sheet


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("`Linux`")) -.-> linux/UserandGroupManagementGroup(["`User and Group Management`"]) linux/UserandGroupManagementGroup -.-> linux/sudo("`Privilege Granting`") subgraph Lab Skills linux/sudo -.-> lab-422624{{"`Linux cupsd Command with Practical Examples`"}} end

Understand the CUPS Printing System

In this step, you will learn about the CUPS (Common Unix Printing System) printing system, which is the standard printing system used in many Linux distributions. CUPS provides a flexible and powerful way to manage printers and print jobs on your system.

First, let's check the status of the CUPS service:

sudo systemctl status cups

Example output:

● cups.service - CUPS Printing Service
     Loaded: loaded (/lib/systemd/system/cups.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2023-04-28 12:34:56 UTC; 1min 23s ago
   Main PID: 1234 (cupsd)
     Status: "Waiting for incoming connections"

As you can see, the CUPS service is running and active on the system.

Next, let's explore the CUPS web interface, which provides a user-friendly way to manage printers and print jobs. Open a web browser and navigate to http://localhost:631. This will take you to the CUPS web interface, where you can perform various tasks such as adding printers, managing print jobs, and configuring printer settings.

Take some time to explore the CUPS web interface and familiarize yourself with its features and functionality.

Manage Printers Using the cupsd Command

In this step, you will learn how to manage printers using the cupsd command, which is the CUPS print daemon. The cupsd command provides a command-line interface for interacting with the CUPS printing system.

First, let's list the available printers on the system:

sudo cupsd -t

Example output:

scheduler is running
0 jobs in the queue
Rendering completed 0 jobs
Processed 0 jobs
Accepted 0 jobs
Rejected 0 jobs
Pending 0 jobs
Stopped 0 jobs
Canceled 0 jobs
Aborted 0 jobs
Completed 0 jobs
Purged 0 jobs

As you can see, there are currently no printers configured on the system.

To add a new printer, you can use the lpadmin command, which is part of the CUPS package. Let's add a new printer named "MyPrinter":

sudo lpadmin -p MyPrinter -v ipp://localhost/printers/MyPrinter -P /usr/share/ppd/cupsfilters/generic.ppd -E

This command creates a new printer named "MyPrinter" with the specified URI and PPD (PostScript Printer Description) file.

To list the available printers again, run:

sudo cupsd -t

Example output:

scheduler is running
0 jobs in the queue
Rendering completed 0 jobs
Processed 0 jobs
Accepted 0 jobs
Rejected 0 jobs
Pending 0 jobs
Stopped 0 jobs
Canceled 0 jobs
Aborted 0 jobs
Completed 0 jobs
Purged 0 jobs
1 printer
MyPrinter accepting requests since Fri 2023-04-28 12:34:56 +0000

Now you can see the newly added "MyPrinter" in the list of available printers.

Configure Printer Settings with cupsd

In this step, you will learn how to configure printer settings using the cupsd command.

First, let's check the current configuration of the "MyPrinter" printer:

sudo cupsd -p MyPrinter -l

Example output:

printer MyPrinter
  State: idle, accepting jobs
  Device URI: ipp://localhost/printers/MyPrinter
  Printer is shared
  Printer is located in .
  Printer is connected
  Printer driver: generic
  Printer is enabled and ready to print

As you can see, the printer is currently in the "idle" state and is accepting jobs.

Now, let's change the printer's default paper size to A4:

sudo lpadmin -p MyPrinter -o media=a4

To verify the change, let's check the printer configuration again:

sudo cupsd -p MyPrinter -l

Example output:

printer MyPrinter
  State: idle, accepting jobs
  Device URI: ipp://localhost/printers/MyPrinter
  Printer is shared
  Printer is located in .
  Printer is connected
  Printer driver: generic
  Printer is enabled and ready to print
  Default paper size: a4

You can see that the default paper size is now set to "a4".

Next, let's pause the printer:

sudo cupsd -p MyPrinter -o printer-state-reasons=paused

To verify the change, check the printer status again:

sudo cupsd -p MyPrinter -l

Example output:

printer MyPrinter
  State: paused, accepting jobs
  Device URI: ipp://localhost/printers/MyPrinter
  Printer is shared
  Printer is located in .
  Printer is connected
  Printer driver: generic
  Printer is disabled and not ready to print
  Default paper size: a4

The printer is now in the "paused" state, and it is not ready to print.

Summary

In this lab, you learned about the CUPS (Common Unix Printing System) printing system, which is the standard printing system used in many Linux distributions. You explored the CUPS web interface, which provides a user-friendly way to manage printers and print jobs. You also learned how to use the cupsd command, the CUPS print daemon, to manage printers from the command line, including listing available printers and adding new ones.

Linux Commands Cheat Sheet

Other Linux Tutorials you may like