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

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

The lpq command is used to show the printer queue status. It provides information about the queued print jobs, such as the job ID, owner, file size, and status. This command is particularly useful for managing print queues and monitoring the progress of printing jobs.

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

Code:

lpq

Motivation: By using the command lpq without any arguments, we can quickly check the queued jobs for the default destination printer. This is useful when we want to get a quick overview of the current print queue and see the status of each job.

Example output:

Rank    Owner   Job     Files                              Total Size
active  john    4       example.pdf                        1024 bytes
active  alice   5       document.txt                       512 bytes
1st     bob     6       report.pdf                         2048 bytes

Explanation:

  • lpq is the command itself that is used to show the printer queue status.

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

Code:

lpq -a -E

Motivation: In some scenarios, we may have multiple printers in a network where encryption is enforced. By using the -a option, we can show the queued jobs for all printers, and the -E option ensures that only printers enforcing encryption are considered. This is helpful when we want to monitor the print queues of all encrypted printers simultaneously.

Example output:

Rank    Owner   Job     Files                              Total Size
active  john    4       example.pdf                        1024 bytes
active  alice   5       document.txt                       512 bytes
active  john    8       report.pdf                         2048 bytes
active  alice   9       presentation.ppt                   3072 bytes

Explanation:

  • -a is the option used to show the queued jobs of all printers.
  • -E is the option used to filter only printers enforcing encryption.

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

Code:

lpq -l

Motivation: When we want to obtain more detailed information about the queued print jobs, we can use the -l option to display the jobs in a long format. This includes additional details such as the job priority, job size, and date and time of submission. This can be useful for troubleshooting print job issues or analyzing the print queue.

Example output:

Rank    Owner   Job     Files                              Total Size     Priority   Date and Time
active  john    4       example.pdf                        1024 bytes    50         2022-01-05 09:30
active  alice   5       document.txt                       512 bytes     20         2022-01-05 10:15
active  john    6       report.pdf                         2048 bytes    30         2022-01-05 11:00

Explanation:

  • -l is the option used to display the queued jobs in a long format, providing more detailed information about each job.

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

Code:

lpq -P destination[/instance]

Motivation: When there are multiple printers or printer classes available, we may want to focus on a specific printer or class to check its queued jobs. By using the -P option followed by the destination and optionally the instance, we can narrow down the output to a specific printer or class. This can be helpful when we need to quickly view the status of print jobs for a particular printer or class.

Example output:

Rank    Owner   Job     Files                              Total Size
active  john    4       example.pdf                        1024 bytes
active  alice   5       document.txt                       512 bytes

Explanation:

  • -P is the option used to specify the printer or class for which we want to show the queued jobs.
  • destination[/instance] is the destination and optionally instance of the printer or class.

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

Code:

lpq +interval

Motivation: In some cases, it may be useful to continuously monitor the printer queue until it becomes empty. By using the +interval argument, we can specify the time interval in seconds at which the lpq command will repeat until all print jobs are completed. This is helpful when we want to keep track of the print queue and take action once it is empty.

Example output:

Rank    Owner   Job     Files                              Total Size
active  john    4       example.pdf                        1024 bytes
active  alice   5       document.txt                       512 bytes
(waiting for queue to become empty...)

Explanation:

  • +interval is the argument used to specify the time interval (in seconds) at which the lpq command will repeat.

Conclusion:

In this article, we discussed various use cases of the lpq command. We explored how to show the queued jobs of the default destination, enforce encryption, display the queue in a long format, show jobs of specific printers or classes, and continuously monitor the queue. By understanding these use cases, users can effectively manage and monitor their print jobs and print queues.

Related Posts

How to use the command `rustup-init.sh` (with examples)

How to use the command `rustup-init.sh` (with examples)

rustup-init.sh is a script used to install rustup and the Rust toolchain.

Read More
How to use the command "git-clone" (with examples)

How to use the command "git-clone" (with examples)

Use Case 1: Clone an Existing Repository into a New Directory git clone remote_repository_location path/to/directory Motivation: This use case allows you to clone an existing repository into a new directory on your local machine.

Read More
Using shfmt (with examples)

Using shfmt (with examples)

Use Case 1: Print a formatted version of a shell script shfmt path/to/file Motivation: One common use case for using shfmt is to print a formatted version of a shell script.

Read More