Linux lpq Command with Practical Examples

LinuxLinuxBeginner
Practice Now

Introduction

In this lab, you will learn how to use the lpq command in Linux to check the status of the print queue and manage print jobs. The lab covers the purpose and syntax of the lpq command, how to check the print queue status, and how to manage print jobs using the lpq command. The content is presented in a clear and concise manner, and the steps are easy to follow.

Linux Commands Cheat Sheet


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("`Linux`")) -.-> linux/PackagesandSoftwaresGroup(["`Packages and Softwares`"]) linux/PackagesandSoftwaresGroup -.-> linux/software("`Linux Software`") subgraph Lab Skills linux/software -.-> lab-422773{{"`Linux lpq Command with Practical Examples`"}} end

Understand the Purpose and Syntax of the lpq Command

In this step, you will learn about the purpose and syntax of the lpq command in Linux. The lpq command is used to check the status of the print queue and manage print jobs.

To understand the purpose of the lpq command, let's first explore its syntax:

$ lpq [options] [printer]

The lpq command has the following options:

  • -a: Display the status of all print queues.
  • -l: Display a long listing, including job IDs, file names, and user names.
  • -P <printer>: Specify the printer to check the queue for.

Now, let's try using the lpq command to check the status of the default print queue:

$ lpq
Rank    Owner   Job     File(s)                         Total Size
active  labex   123     document.pdf                    1234567 bytes
1st     labex   124     report.docx                     2345678 bytes

The output shows the current status of the print queue, including the job rank, owner, job ID, file name, and total size of the print job.

Example output:

Rank    Owner   Job     File(s)                         Total Size
active  labex   123     document.pdf                    1234567 bytes
1st     labex   124     report.docx                     2345678 bytes

In the next step, you will learn how to check the print queue status in more detail using the lpq command.

Check the Print Queue Status Using the lpq Command

In this step, you will learn how to use the lpq command to check the status of the print queue in more detail.

First, let's check the status of the default print queue:

$ lpq
Rank    Owner   Job     File(s)                         Total Size
active  labex   123     document.pdf                    1234567 bytes
1st     labex   124     report.docx                     2345678 bytes

The output shows the current print jobs in the queue, including the job rank, owner, job ID, file name, and total size.

You can also use the -l option to display a long listing with more details:

$ lpq -l
Rank   Owner   Job     File(s)                         Total Size
active labex   123     document.pdf                    1234567 bytes
        labex
1st    labex   124     report.docx                     2345678 bytes
        labex

The long listing includes additional information such as the user name associated with each print job.

To check the status of a specific printer, you can use the -P option followed by the printer name:

$ lpq -P printer1
Rank    Owner   Job     File(s)                         Total Size
active  labex   123     document.pdf                    1234567 bytes
1st     labex   124     report.docx                     2345678 bytes

This will display the status of the print queue for the specified printer.

Example output:

Rank    Owner   Job     File(s)                         Total Size
active  labex   123     document.pdf                    1234567 bytes
1st     labex   124     report.docx                     2345678 bytes

In the next step, you will learn how to manage print jobs using the lpq command.

Manage Print Jobs with the lpq Command

In this step, you will learn how to manage print jobs using the lpq command.

First, let's check the current status of the print queue:

$ lpq
Rank    Owner   Job     File(s)                         Total Size
active  labex   123     document.pdf                    1234567 bytes
1st     labex   124     report.docx                     2345678 bytes

Suppose you want to cancel a print job. You can use the lprm command to remove a job from the queue:

$ lprm 124

This will remove the print job with ID 124 from the queue.

You can also use the lpq command to check the updated status of the queue:

$ lpq
Rank    Owner   Job     File(s)                         Total Size
active  labex   123     document.pdf                    1234567 bytes

The job with ID 124 has been removed from the queue.

If you want to pause or resume a print job, you can use the lpc command:

$ lpc hold 123
$ lpq
Rank    Owner   Job     File(s)                         Total Size
active* labex   123     document.pdf                    1234567 bytes

$ lpc release 123
$ lpq
Rank    Owner   Job     File(s)                         Total Size
active  labex   123     document.pdf                    1234567 bytes

The lpc hold command pauses the print job, and the lpc release command resumes the job.

Example output:

$ lpq
Rank    Owner   Job     File(s)                         Total Size
active  labex   123     document.pdf                    1234567 bytes
1st     labex   124     report.docx                     2345678 bytes

$ lprm 124
$ lpq
Rank    Owner   Job     File(s)                         Total Size
active  labex   123     document.pdf                    1234567 bytes

$ lpc hold 123
$ lpq
Rank    Owner   Job     File(s)                         Total Size
active* labex   123     document.pdf                    1234567 bytes

$ lpc release 123
$ lpq
Rank    Owner   Job     File(s)                         Total Size
active  labex   123     document.pdf                    1234567 bytes

In this step, you learned how to manage print jobs using the lpq, lprm, and lpc commands.

Summary

In this lab, you learned about the purpose and syntax of the lpq command in Linux, which is used to check the status of the print queue and manage print jobs. You explored the different options available with the lpq command, such as displaying the status of all print queues, showing a long listing with job details, and specifying a particular printer to check. You also learned how to use the lpq command to check the status of the default print queue, which provides information about the current print jobs, including their rank, owner, job ID, file name, and total size.

Linux Commands Cheat Sheet

Other Linux Tutorials you may like