命令行大全

lpstat

rose1 发表于 2020-09-26 06:04浏览次数:

在类似Unix的操作系统上,lpstat命令列出LP打印服务的状态。

查看英文版

目录:

1 lpstat 运行系统环境

2 lpstat 说明

3 lpstat 语法

4 lpstat 例子

lpstat 运行系统环境

Linux

lpstat 说明

lpstat显示有关当前类,作业和打印机的状态信息。当不带任何参数运行时,lpstat将列出当前用户排队的作业。

lpstat现在是CUPS(通用Unix打印系统)的一部分。在使用lpstat和相关工具(例如lpr)之前,您可能需要安装CUPS 。

安装CUPS

如果您正在运行Debian或使用APT软件包管理系统的Debian衍生的Linux系统(如Ubuntu),则可以通过运行以下命令来安装它们:

sudo apt-get update && sudo apt-get install cups cups-client lpr

此命令将在您的系统上安装Common Unix Printing System。现在,您应该可以通过将任何Web浏览器定向到以下地址来设置CUPS:http:// localhost:631

这样做将打开基于Web的CUPS配置屏幕,该屏幕应类似于以下内容:

CUPS

然后,从命令行使用以下命令将您的用户添加到组lpadmin中:

sudo adduserlpadmin

此命令会将您添加到允许在系统上管理打印机的用户组。

现在,您应该可以使用lpstat检查打印机的状态和打印作业。

lpstat displays status information about the current classes, jobs, and printers. When run with no arguments, lpstat will list jobs queued by the current user.

lpstat is now part of the CUPS (Common Unix Printing System). You may need to install CUPS before using lpstat, and related tools such as lpr.

Installing CUPS

If you're operating Debian, or a Debian-derived Linux system like Ubuntu that uses the APT package managements system, you can install them by running the following command:

sudo apt-get update && sudo apt-get install cups cups-client lpr

This command will install the Common Unix Printing System on your system. You should now be able to set up CUPS by directing any web browser to the address: http://localhost:631

Doing so will open a web-based CUPS configuration screen, which should look something like this:

CUPS

Then, from the command line, add your user to the group lpadmin with the command:

sudo adduserlpadmin

This command will add you to the group of users allowed to administer printers on your system.

You should now be able to check the status of your printers and your print jobs by using lpstat.

查看英文版

查看中文版

lpstat 语法

lpstat [ -E ] [ -H ] [ -U username< ] [ -h hostname<[:port<] ] [ -l ] 
       [ -W which-jobs< ] [ -a [ destination<(s) ] ] [ -c [ class<(es) ] ] 
       [ -d ] [ -o [ destination<(s) ] ] [ -p [ printer<(s) ] ] [ -r ] [ -R ] 
       [ -s ] [ -t ] [ -u [ user<(s) ] ] [ -v [ printer<(s) ] ]

选件

-E 连接到服务器时强制加密。
-H 显示服务器主机名和端口。
-R 显示打印作业的排名。
-U username< 指定备用用户名;就像您是用户username一样运行lpstat。此选项需要超级用户特权。
-W which-jobs< 指定要显示,已完成或未完成的作业(默认)。该选项必须出现在-o选项或任何打印机名称之前,否则,将在对调度程序的请求中使用默认值(未完成)。
-a [printer(s)<] 显示打印机队列的接受状态。如果未指定打印机,则列出所有打印机。
-c [class(es)<] 显示打印机类和属于它们的打印机。如果未指定任何类别,则将列出所有类别。
-d 显示当前的默认目的地。
-h server<[:port<] 指定备用服务器。
-l 显示打印机,类或作业的长列表。
-o [destination(s)<] 显示指定目的地上的作业队列。如果未指定目的地,则显示所有作业。
-p [printer(s)<] 显示打印机以及是否启用了打印功能。如果未指定打印机,则列出所有打印机。
-r 显示CUPS服务器是否正在运行。
-s 显示状态摘要,包括默认目的地,类及其成员打印机的列表以及打印机及其关联设备的列表。此选项等效于使用“ -d ”,“ -c ”和“ -v ”选项。
-t 显示所有状态信息。此选项等效于使用“ -r ”,“ -d ”,“ -c ”,“ -v ”,“ -a ”,“ -p ”和“ -o ”选项。
-u [user(s)<] 显示指定用户排队的打印作业列表。如果未指定用户,则列出当前用户排队的作业。
-v [printer(s)<] 显示打印机和连接的设备。如果未指定打印机,则列出所有打印机。
lpstat [ -E ] [ -H ] [ -U username< ] [ -h hostname<[:port<] ] [ -l ] 
       [ -W which-jobs< ] [ -a [ destination<(s) ] ] [ -c [ class<(es) ] ] 
       [ -d ] [ -o [ destination<(s) ] ] [ -p [ printer<(s) ] ] [ -r ] [ -R ] 
       [ -s ] [ -t ] [ -u [ user<(s) ] ] [ -v [ printer<(s) ] ]

Options

-E Forces encryption when connecting to the server.
-H Shows the server hostname and port.
-R Shows the ranking of print jobs.
-U username< Specifies an alternate username; runs lpstat as if you were user username<. This option requires superuser privileges.
-W which-jobs< Specifies which jobs to show, completed or not-completed (the default). This option must appear before the -o option or any printer names, otherwise the default (not-completed) value will be used in the request to the scheduler.
-a [printer(s)<] Shows the accepting state of printer queues. If no printers are specified then all printers are listed.
-c [class(es)<] Shows the printer classes and the printers that belong to them. If no classes are specified then all classes are listed.
-d Shows the current default destination.
-h server<[:port<] Specifies an alternate server.
-l Shows a long listing of printers, classes, or jobs.
-o [destination(s)<] Shows the jobs queue on the specified destinations. If no destinations are specified all jobs are shown.
-p [printer(s)<] Shows the printers and whether or not they are enabled for printing. If no printers are specified then all printers are listed.
-r Shows whether the CUPS server is running.
-s Shows a status summary, including the default destination, a list of classes and their member printers, and a list of printers and their associated devices. This option is equivalent to using the "-d", "-c", and "-v" options.
-t Shows all status information. This option is equivalent to using the "-r", "-d", "-c", "-v", "-a", "-p", and "-o" options.
-u [user(s)<] Shows a list of print jobs queued by the specified users. If no users are specified, lists the jobs queued by the current user.
-v [printer(s)<] Shows the printers and the attached devices. If no printers are specified then all printers are listed.

查看英文版

查看中文版

lpstat 例子

lpstat -t

显示所有打印机信息。输出将类似于以下内容:

scheduler is running
system default destination: PDF
device for Lexmark_Pro700_Series: 
usb://Lexmark/Pro700%20Series?serial=90T7099T1914144&interface=1
device for PDF: cups-pdf:/
Lexmark_Pro700_Series accepting requests since Mon 18 Aug 2014 03:46:06 PM EDT
PDF accepting requests since Sun 17 Aug 2014 09:51:41 PM EDT
printer Lexmark_Pro700_Series disabled since Mon 18 Aug 2014 03:46:06 PM EDT -
        Unplugged or turned off
printer PDF is idle.  enabled since Sun 17 Aug 2014 09:51:41 PM EDT
lpstat -p

显示所有已安装的打印机。输出将类似于以下内容:

printer Lexmark_Pro700_Series disabled since Mon 18 Aug 2014 03:46:06 PM EDT -
        Unplugged or turned off
printer PDF is idle.  enabled since Sun 17 Aug 2014 09:51:41 PM EDT
lpstat -a

仅显示当前正在接受打印请求的那些打印机。输出将类似于以下内容:

Lexmark_Pro700_Series accepting requests since Mon 18 Aug 2014 03:46:06 PM EDT
PDF accepting requests since Sun 17 Aug 2014 09:51:41 PM EDT

请注意,当前关闭电源的打印机仍将接受请求。这些请求将一直保留在队列中,直到打开设备电源或使用lprm删除该请求为止。

lpstat -d

显示当前默认的打印机。输出将类似于以下内容:

system default destination: Lexmark_Pro700_Series
lpstat -o

显示所有活动的打印作业。输出将类似于以下内容:

Rank   Owner    Job  Files                                       Total Size
1st    hope     1    budget.txt                                  2315 bytes
2nd    hope     2    /home/hope/docs/userlist.txt                5452 bytes
3rd    hope     4    (standard input)                            52954 bytes
4th    hope     5    /tmp/vroAdm2/1                              5827 bytes
lpstat -t

Display all printer information. Output will resemble the following:

scheduler is running
system default destination: PDF
device for Lexmark_Pro700_Series: 
usb://Lexmark/Pro700%20Series?serial=90T7099T1914144&interface=1
device for PDF: cups-pdf:/
Lexmark_Pro700_Series accepting requests since Mon 18 Aug 2014 03:46:06 PM EDT
PDF accepting requests since Sun 17 Aug 2014 09:51:41 PM EDT
printer Lexmark_Pro700_Series disabled since Mon 18 Aug 2014 03:46:06 PM EDT -
        Unplugged or turned off
printer PDF is idle.  enabled since Sun 17 Aug 2014 09:51:41 PM EDT
lpstat -p

Display all installed printers. Output will resemble the following:

printer Lexmark_Pro700_Series disabled since Mon 18 Aug 2014 03:46:06 PM EDT -
        Unplugged or turned off
printer PDF is idle.  enabled since Sun 17 Aug 2014 09:51:41 PM EDT
lpstat -a

Display only those printers that are currently accepting print requests. Output will resemble the following:

Lexmark_Pro700_Series accepting requests since Mon 18 Aug 2014 03:46:06 PM EDT
PDF accepting requests since Sun 17 Aug 2014 09:51:41 PM EDT

Note that printers that are currently powered off will still accept requests; these requests will remain in the queue until the device is powered on, or the request is removed with lprm.

lpstat -d

Displays which printer is currently the default. Output will resemble the following:

system default destination: Lexmark_Pro700_Series
lpstat -o

Display all active print jobs. Output will resemble the following:

Rank   Owner    Job  Files                                       Total Size
1st    hope     1    budget.txt                                  2315 bytes
2nd    hope     2    /home/hope/docs/userlist.txt                5452 bytes
3rd    hope     4    (standard input)                            52954 bytes
4th    hope     5    /tmp/vroAdm2/1                              5827 bytes

查看英文版

查看中文版