How to Use the Command 'lpq' (with Examples)

How to Use the Command 'lpq' (with Examples)

The lpq command is a utility used in Unix and Unix-like operating systems to display the status of print queues. It interacts with the Common Unix Printing System (CUPS) to show details of print jobs that are waiting to be processed by a printer. This tool is especially invaluable for system administrators and users who need to manage and monitor print jobs effectively. Utilizing lpq can help troubleshoot and streamline printing tasks by providing insights into the queue status across different printers.

Use case 1: Show the queued jobs of the default destination

Code:

lpq

Motivation:
The primary motivation for using this command is to quickly check the list of jobs waiting to be processed on the default printer. This is particularly useful if you want to know if your document is successfully queued, or if a printer is currently processing other tasks before reaching yours.

Explanation:
The lpq command without any additional options will automatically direct itself to the default printer set in the system. It retrieves and displays a list of all print jobs that are lined up on this printer. This output includes basic details such as the job IDs, owners of the print jobs, file names, and the status of each job.

Example Output:

Printer: HP_LaserJet_1020
Rank    Owner   Job     File(s)          Total Size
active  user1   23      report.pdf        1024 bytes
1st     user2   24      image.jpg         2048 bytes

Use case 2: Show the queued jobs of all printers enforcing encryption

Code:

lpq -a -E

Motivation:
This use case focuses on security-conscious environments where encryption is mandatory. By enforcing encryption, you ensure that the print queue data is secure from unauthorized access, which is vital in protecting sensitive or confidential information being transmitted to and from print devices.

Explanation:

  • -a: This option instructs lpq to display jobs from all available printers rather than just the default printer.
  • -E: This flag enforces encryption, ensuring that any data exchanged between the system and printers uses a secure method (usually TLS).

Example Output:

Printer: HP_ColorLaserJet (encrypted)
Rank    Owner   Job     File(s)          Total Size
1st     admin   25      contract.docx    4096 bytes

Printer: Canon_iR_Adv_C5030 (encrypted)
Rank    Owner   Job     File(s)          Total Size
active  user3   26      thesis.pdf       5120 bytes

Use case 3: Show the queued jobs in a long format

Code:

lpq -l

Motivation:
This format is ideal for users and administrators who need a thorough breakdown of each print job in the queue. A detailed view can aid in diagnosing issues with specific jobs, such as unusually large file sizes or mismatches in expected output formats.

Explanation:

  • -l: The long format option expands the amount of detail shown for each job. It includes additional information such as job titles, complete paths to the files, submission times, and more. This depth of information provides comprehensive insights into what is happening with the queued jobs.

Example Output:

Printer: HP_LaserJet_1022n
Job ID.       : 27
Owner         : user4
File(s)       : /home/user4/datasheet.xlsx
Job Title     : Datasheet
Submission    : 2023-10-05 14:32:10
Total Size    : 3072 bytes
Status        : pending

Use case 4: Show the queued jobs of a specific printer or class

Code:

lpq -P destination[/instance]

Motivation:
Targeting a specific printer or printer class allows users to directly manage and view print jobs from that particular resource. This is useful in environments with multiple printers, ensuring users or administrators are interacting only with the relevant printer queues.

Explanation:

  • -P: This option specifies which printer or class to query. The destination represents the printer’s name, while [/instance] specifies any particular instance of the printer if applicable. By directing queries to a particular printer, users can effectively manage specific print operations or diagnose issues unique to that device.

Example Output:

Printer: Epson_WorkForce_C5790
Rank    Owner   Job     File(s)            Total Size
2nd     user5   28      layout_design.dwg  6144 bytes

Use case 5: Show the queued jobs once every n seconds until the queue is empty

Code:

lpq +interval

Motivation:
Using this command is beneficial for ongoing monitoring of print queues, particularly in active environments where print jobs are constantly being added or completed. Setting up periodic checks enable users or administrators to maintain visibility into queue statuses without the need to repetitively issue manual commands.

Explanation:

  • +interval: This part of the command specifies how often lpq should refresh and display the queue status. The interval variable is defined by the user and represents the number of seconds between each query. This continuous refreshing stops once the queue is cleared.

Example Output over time:

(Refreshing every 10 seconds)
Printer: Brother_HL_L2380DW
Rank    Owner   Job     File(s)          Total Size
1st     user6   29      memo.txt         1024 bytes
(active - next refresh in 10s)

(after 10 seconds)
Printer: Brother_HL_L2380DW
Queue empty (checked every 10s)

Conclusion:

The lpq command is a versatile tool for managing and monitoring print queues within Unix-like operating systems. From quickly checking the queue for default printers to ensuring secure print job transmission, the command provides various configurations to meet specific needs. Whether users need detailed job information or automated status updates on print queues, lpq offers a simple yet powerful solution to optimize printing workflows.

Related Posts

How to use the command 'btrfs property' (with examples)

How to use the command 'btrfs property' (with examples)

The btrfs property command is a versatile tool for managing properties on BTRFS filesystem objects, including files, directories, subvolumes, filesystems, and devices.

Read More
How to Use the Command 'molecule' (with Examples)

How to Use the Command 'molecule' (with Examples)

Molecule is a specialized tool for testing Ansible roles, ensuring that they work as expected in various environments.

Read More
Exploring 'dnsx': A Comprehensive DNS Toolkit (with examples)

Exploring 'dnsx': A Comprehensive DNS Toolkit (with examples)

‘dnsx’ is a powerful and versatile DNS toolkit aimed at efficiently performing a variety of DNS queries.

Read More