How to use the command lpstat (with examples)

How to use the command lpstat (with examples)

The lpstat command is used to show status information about printers on a machine. It can provide information about printers, print jobs, and printer defaults. This command is particularly useful for managing and troubleshooting printing tasks in a Linux or UNIX environment.

Use case 1: List printers present on the machine and whether they are enabled for printing

Code:

lpstat -p

Motivation: This use case is helpful when you want to get a list of all printers connected to the machine and check if they are enabled for printing. It can be useful for troubleshooting printer connectivity or setting up print queues.

Explanation:

  • -p: The -p option is used to list printers and their current status.

Example output:

printer HP_LaserJet_5000 is idle.  enabled since Fri 01 May 2020 09:24:58 AM EDT
printer EPSON_Stylus_Photo_1400 is idle.  enabled since Fri 01 May 2020 09:24:58 AM EDT

Use case 2: Show the default printer

Code:

lpstat -d

Motivation: This use case is helpful when you want to find out the default printer set up on the machine. It can be useful when you need to specify a printer for print jobs or check if the currently set default printer is correct.

Explanation:

  • -d: The -d option is used to display the default printer.

Example output:

system default destination: HP_LaserJet_5000

Use case 3: Display all available status information

Code:

lpstat -t

Motivation: This use case is useful when you need comprehensive information about the printers on the machine, including their current status, job IDs, and printer capabilities. It can help in diagnosing printer issues or monitoring print jobs.

Explanation:

  • -t: The -t option is used to display all available status information.

Example output:

scheduler is running
system default destination: HP_LaserJet_5000
device for HP_LaserJet_5000: parallel:/dev/lp0
device for EPSON_Stylus_Photo_1400: usb://EPSON/Stylus%20Photo%201400
HP_LaserJet_5000 accepting requests since Fri 01 May 2020 09:24:58 AM EDT
EPSON_Stylus_Photo_1400 accepting requests since Fri 01 May 2020 09:24:58 AM EDT
printer HP_LaserJet_5000 now printing HP_LaserJet_5000-1.  enabled since Fri 01 May 2020 09:24:58 AM EDT
printer EPSON_Stylus_Photo_1400 now printing EPSON_Stylus_Photo_1400-2.  enabled since Fri 01 May 2020 09:24:58 AM EDT

Use case 4: Show a list of print jobs queued by the specified user

Code:

lpstat -u user

Motivation: This use case is helpful when you want to check the print jobs queued by a specific user. It can be useful for monitoring the progress of print jobs and resolving any potential issues.

Explanation:

  • -u user: The -u option is used to specify the user whose print jobs are to be displayed.

Example output:

HP_LaserJet_5000-1       user             10240   Fri 01 May 2020 09:30:21 AM EDT
EPSON_Stylus_Photo_1400-2       user             20480   Fri 01 May 2020 09:30:45 AM EDT

Conclusion:

The lpstat command is a versatile tool for managing and troubleshooting printers in a Linux or UNIX environment. It provides valuable information about printer status, print jobs, and printer settings. By using the various options available with lpstat, users can effectively monitor and control printing tasks on their system.

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 used to get, set, or list properties for a given btrfs filesystem object, such as files, directories, subvolumes, filesystems, or devices.

Read More
8 Different Use Cases of the `auditd` Command (with examples)

8 Different Use Cases of the `auditd` Command (with examples)

Use Case 1: Start the daemon auditd Motivation: Starting the auditd daemon is the first step to enable auditing on a Linux system.

Read More
How to use the command 'e4defrag' (with examples)

How to use the command 'e4defrag' (with examples)

The ’e4defrag’ command is designed to defragment an ext4 filesystem. Defragmentation is the process of rearranging the data on a filesystem to optimize performance and improve disk space utilization.

Read More