命令行大全

lpr

rose1 发表于 2020-09-29 09:11浏览次数:

在类似Unix的操作系统上,lpr命令提交打印作业。

查看英文版

目录:

1 lpr 运行系统环境

2 在Linux中打印

3 安装lpr,lpd和CUPS

4 lpr 说明

5 lpr 语法

6 lpr 例子

lpr 运行系统环境

Linux

在Linux中打印

在Linux中打印最简单的方法是cat一个文件到打印设备,就像这样:

sudo cat my-file-to-print.txt > /dev/lp

该命令的作用是读取文件my-file-to-print.txt并将其逐字节发送到打印机设备/ dev / lp。(此名称是设备的符号链接,并且可能有所不同。您的打印机可能是另一个设备名称,例如lp0。)通常cat将其输出发送到标准输出(终端),但是在这里我们将其重定向到设备/ dev / lp使用>运算符。只有超级用户才能直接写入打印机设备,这就是为什么我们必须在命令前加上sudo的原因。

lpr与此相比更加友好,并且允许您将打印作业排队。最重要的是,它使您无需超级用户即可访问打印机设备。

The simplest way to print in Linux is to cat a file to the printing device, like this:

sudo cat my-file-to-print.txt > /dev/lp

What this command does is read the file my-file-to-print.txt and send it, byte by byte, to the printer device /dev/lp. (This name is a symbolic link to the device, and may vary. Your printer may be another device name, for instance lp0.) Normally cat sends its output to standard output (the terminal) but here we redirect it to the device /dev/lp with the > operator. Only the superuser can write directly to the printer device, which is why we have to preface the command with sudo.

lpr is much more user-friendly than this, however, and it allows you to queue print jobs. And most importantly, it allows you to access the printer device without being the superuser.

查看英文版

查看中文版

安装lpr,lpd和CUPS

该方法LPR作品,概括地说,就是:它的文件和手可打印数据超过了Linux打印读取守护进程,LPD。lpd是Linux的旧版软件,但在大多数Linux发行版使用的现代系统CUPS(通用Unix打印系统)下受支持。

您可能需要手动安装CUPS和lpr本身,以这种方式打印。如果您正在运行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

此命令会将您添加到允许在系统上管理打印机的用户组。现在返回CUPS Web管理面板,并在“管理”选项卡下,选择“添加打印机”。系统将提示您输入用户名和密码,并且应该可以设置新的打印机。

The way lpr works, in a nutshell, is: it reads in the file and hands the printable data over to the linux printing daemon, lpdlpd is a legacy piece of software for Linux, but it is supported under the modern system used by most Linux distributions, CUPS (the Common Unix Printing System).

You may need to manually install CUPS, and lpr itself, to print this way. 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. Now go back to the CUPS web administration panel, and under the administration tab, select "Add Printer." You will be prompted for your username and password, and you should be able to set up a new printer.

查看英文版

查看中文版

lpr 说明

lpr提交文件进行打印。在命令行上命名的文件将发送到命名打印机(如果未指定目标,则为默认目标)。如果命令行上未列出任何文件,则lpr从标准输入读取打印文件。
lpr submits files for printing. Files named on the command line are sent to the named printer (or the default destination if no destination is specified). If no files are listed on the command-line, lpr reads the print file from the standard input.

查看英文版

查看中文版

lpr 语法

lpr [ -E ] [ -H server[:port] ] [ -U username ] [ -P destination[/instance] ] 
    [ -# num-copies [ -h ] [ -l ] [ -m ] [ -o option[=value] ] [ -p] [ -q ] 
    [ -r ] [ -C/J/T title ] [ file(s) ]

选件

-E 连接到服务器时强制加密。
-H 服务器 [ :端口 ] 指定备用服务器。
-C “ 名称

-J “ 名称

-T “ 名称
设置作业名称。
-P 目标 [ / 实例 ] 将文件打印到命名打印机。
-U 用户名 指定备用用户名。
-# copies 将打印份数设置为1100。
-h 禁用横幅打印。此选项等效于“ -o job-sheets = none ”。
-l 指定打印文件已针对目标进行了格式化,并且应在不进行过滤的情况下发送。此选项等效于“ -o raw ”。
-m 作业完成后发送电子邮件。
-o 选项 [ = 值 ] 设置作业选项。
-p 指定应使用带有日期,时间,作业名称和页码的阴影标题格式化打印文件。此选项等效于“ -o prettyprint ”,仅在打印文本文件时有用。
-q 保留作业进行打印。
-r 指定在打印命名的打印文件后应将其删除。
lpr [ -E ] [ -H server[:port] ] [ -U username ] [ -P destination[/instance] ] 
    [ -# num-copies [ -h ] [ -l ] [ -m ] [ -o option[=value] ] [ -p] [ -q ] 
    [ -r ] [ -C/J/T title ] [ file(s) ]

Options

-E Forces encryption when connecting to the server.
-H server[:port] Specifies an alternate server.
-C "name"

-J "name"

-T "name"
Sets the job name.
-P destination[/instance] Prints files to the named printer.
-U username Specifies an alternate username.
-# copies Sets the number of copies to print from 1 to 100.
-h Disables banner printing. This option is equivalent to "-o job-sheets=none".
-l Specifies that the print file is already formatted for the destination and should be sent without filtering. This option is equivalent to "-o raw".
-m Send an email when a job is complete.
-o option[=value] Sets a job option.
-p Specifies that the print file should be formatted with a shaded header with the date, time, job name, and page number. This option is equivalent to "-o prettyprint" and is only useful when printing text files.
-q Hold job for printing.
-r Specifies that the named print files should be deleted after printing them.

查看英文版

查看中文版

lpr 例子

lpr myfile.txt

提交请求以打印文件myfile.txt。

cat myfile.txt | lpr

cat一个文件( myfile.txt),管道输出到 LPR,其从标准输入读取其内容,并将其发送到用于打印的打印守护进程。

lpr -#3 myfile.txt

打印myfile.txt3个副本。

lpr myfile.txt

Submits a request to print the file myfile.txt.

cat myfile.txt | lpr

cat a file (myfile.txt), piping the output to lpr, which reads its contents from standard input and sends it to the print daemon for printing.

lpr -#3 myfile.txt

Print 3 copies of myfile.txt.

查看英文版

查看中文版