How to Use the 'lpstat' Command (with Examples)
The lpstat
command is a utility in Unix and Unix-like operating systems that provides a variety of status information related to the print system. It allows users to check printer statuses, examine print jobs, and determine default printer settings, among other functionalities. This command is particularly useful for users who manage multiple printers or need to troubleshoot printing issues.
Use case 1: List Printers Present on the Machine and Whether They Are Enabled for Printing
Code:
lpstat -p
Motivation: This operation is essential for users who manage a network of printers and need to ensure all are operational and ready for use. By listing all the printers and checking whether they are enabled, a user can quickly diagnose issues or confirm the setup for newly added devices. This information is crucial when setting up a printing environment or maintaining an existing one with multiple printers available.
Explanation:
lpstat
: The base command to access print system information.-p
: This option specifically lists all available printers, indicating their current state. The state information can include whether the printer is accepting jobs or if it has been disabled due to an error or for maintenance.
Example Output:
printer HP_LaserJet_Pro disabled since Mon 04 Oct 2023 10:20:43 AM EDT -
reason unknown
printer Office_ColorJet enabled since Wed 06 Oct 2023 08:43:11 AM EDT
printer Canon_IntelligentPrint enabled since Thu 07 Oct 2023 02:15:51 PM EDT
Use case 2: Show the Default Printer
Code:
lpstat -d
Motivation: Knowing which printer is set as the default is vital for environments where there are multiple printer options. This scenario is common in shared office spaces or labs. Users and administrators need to ensure that jobs are being sent to the correct default printer to avoid unnecessary delays or confusion.
Explanation:
lpstat
: The command used to query print system status information.-d
: This flag shows the current default destination, i.e., the printer that is set as the default for print jobs.
Example Output:
system default destination: Office_ColorJet
Use case 3: Display All Available Status Information
Code:
lpstat -t
Motivation: For comprehensive printer management, having a full status overview can be incredibly beneficial. When troubleshooting or verifying system setup, this command provides a complete snapshot of the printing environment, including printer statuses, queue statuses, and system defaults. This holistic picture can save time when diagnosing issues.
Explanation:
lpstat
: Command that retrieves printing system information.-t
: This verbose option provides a complete display of printer status information, including complete lists of printers, classes, and print jobs queued.
Example Output:
scheduler is running
system default destination: Office_ColorJet
device for HP_LaserJet_Pro: usb://HP/LaserJet_Pro
device for Office_ColorJet: dnssd://Office_ColorJet
device for Canon_IntelligentPrint: dnssd://Canon_IntelligentPrint
HP_LaserJet_Pro accepting requests since Mon 04 Oct 2023 10:20:43 AM EDT
Office_ColorJet accepting requests since Wed 06 Oct 2023 08:43:11 AM EDT
Canon_IntelligentPrint accepting requests since Thu 07 Oct 2023 02:15:51 PM EDT
...
Use case 4: List Print Jobs Queued by a Specific User
Code:
lpstat -u user
Motivation: In environments with shared printer access, it is often necessary to keep track of who is sending print jobs and ensure that users are using resources efficiently. By listing jobs for a specific user, administrators or users themselves can monitor print activities, clear up any stalled jobs, or ensure they’re sending multiple jobs correctly.
Explanation:
lpstat
: This command fetches print system details.-u
: This flag lets the user specify which user’s job queue should be examined. Replaceuser
with the actual username to filter print jobs by that user.
Example Output:
office_colorjay-14 user1 1024 Sat 09 Oct 2023 01:10:23 PM EDT
canon_intelligentprint-15 user1 2048 Sat 09 Oct 2023 01:12:47 PM EDT
Conclusion:
The lpstat
command is a powerful tool for managing printers and print jobs within a Unix-like operating system. It provides vital information that can help in monitoring printer status, identifying the default printer, obtaining comprehensive system status, and tracking or managing print jobs by user. With its various options, lpstat
is essential for anyone who needs to ensure efficient and trouble-free operation of print services.