Introduction
In this lab, we will explore the lpd (Line Printer Daemon) command, a key tool for managing print jobs in Linux. We will learn how to configure the lpd daemon, manage print jobs, and perform various printing-related tasks. The lab covers the introduction to the lpd command, configuring the lpd daemon, and managing print jobs with lpd. The steps provided include checking the status of the lpd service, creating and enabling new print queues, and using commands like lpstat and lprm to manage the printing process.
Introduction to the lpd Command
In this step, we will explore the lpd (Line Printer Daemon) command, which is a key tool for managing print jobs in Linux. The lpd command is responsible for handling the printing process, including accepting print requests, managing print queues, and communicating with printers.
First, let's check the status of the lpd service on our Ubuntu 22.04 Docker container:
sudo systemctl status lpd
Example output:
● lpd.service - LPD Line Printer Daemon
Loaded: loaded (/lib/systemd/system/lpd.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2023-04-21 12:34:56 UTC; 1min 23s ago
Main PID: 1234 (lpd)
Tasks: 1 (limit: 4915)
Memory: 1.1M
CGroup: /system.slice/lpd.service
└─1234 /usr/sbin/lpd
As we can see, the lpd service is active and running on our system. The lpd daemon is responsible for managing the printing process, including accepting print requests, managing print queues, and communicating with printers.
Next, let's explore some basic commands for interacting with the lpd service:
## List available print queues
sudo lpstat -a
## View the status of the print queue
sudo lpstat -t
## Cancel a print job
sudo lprm job_id
These commands allow you to view the available print queues, check the status of the print queue, and cancel a specific print job.
Configuring the lpd Daemon
In this step, we will learn how to configure the lpd (Line Printer Daemon) service on our Ubuntu 22.04 Docker container.
First, let's create a new print queue. We'll use the lpadmin command to create a new print queue named "myprinter":
sudo lpadmin -p myprinter -v file:/dev/null -P /usr/share/ppd/cups-pdf.ppd -E
This command creates a new print queue named "myprinter" and associates it with the CUPS-PDF virtual printer driver.
Next, let's enable the new print queue:
sudo enable-printer myprinter
Now, let's verify that the new print queue has been created and enabled:
sudo lpstat -a
Example output:
myprinter accepting requests since Mon 01 Jan 2001 12:00:00 AM UTC
The output shows that the "myprinter" queue is now accepting print requests.
To further configure the lpd service, we can edit the /etc/printcap file, which is the configuration file for the lpd service. This file contains information about the available print queues, their settings, and other configuration options.
Open the /etc/printcap file using the nano text editor:
sudo nano /etc/printcap
In the file, you can add or modify entries for your print queues. For example, you can set the default printer, configure printer options, or specify the location of the printer.
After making any changes, save the file and restart the lpd service:
sudo systemctl restart lpd
This will apply the new configuration changes to the lpd service.
Managing Print Jobs with lpd
In this final step, we will learn how to manage print jobs using the lpd command.
First, let's create a sample text file to print:
echo "This is a test print job." > ~/project/test_print.txt
Now, let's submit the file to the "myprinter" print queue:
lpr ~/project/test_print.txt
This will send the "test_print.txt" file to the "myprinter" print queue for printing.
To view the current print jobs in the queue, use the lpq command:
sudo lpq myprinter
Example output:
myprinter is ready
Rank Owner Job File(s) Total Size
active labex 123 test_print.txt 24 bytes
The output shows that the "test_print.txt" file is currently being printed as job 123.
If you need to cancel a print job, use the lprm command:
sudo lprm 123
This will cancel the print job with ID 123.
Finally, let's check the print queue again to verify that the job has been removed:
sudo lpq myprinter
Example output:
myprinter is ready
no entries
The output shows that the print queue is now empty, indicating that the print job has been successfully canceled.
Summary
In this lab, we explored the lpd (Line Printer Daemon) command, a key tool for managing print jobs in Linux. We learned how to check the status of the lpd service, list available print queues, view the status of the print queue, and cancel a specific print job. We then configured the lpd daemon by creating a new print queue and associating it with the CUPS-PDF virtual printer driver, and enabled the new print queue. These steps provide a solid foundation for managing printing processes on a Linux system.



