Linux lpr Command
lpr (line printer remote) is a command used to print files on Linux and Unix systems.
lpr sends files to the print queue, using the system-configured default printer or a specified printer.
lpr can be used to send data to a local or remote host for processing.
Syntax
lpr [选项] [文件...]
Common options:
-P <打印机名>: Specify the printer to use. If not specified, the system default printer is used.-# <Number of copies>: Specify the number of copies.-o <选项>: Specify printing options, such as duplex printing, page range, etc.-h: Do not print the title page.-C <class>: Specify the job class.-J <job>: Specify the job name.-T <title>: Specify the job title.
Examples
Print a file:
lpr myfile.txt
Print with a specified printer:
lpr -P myprinter myfile.txt
Print multiple copies:
lpr -# 3 myfile.txt
Do not print the title page:
lpr -h myfile.txt
Specify printing options (e.g., duplex printing):
lpr -o sides=two-sided-long-edge myfile.txt
Duplex printing:
lpr -o sides=two-sided-long-edge myfile.txt
Specify page range:
lpr -o page-ranges=1-5 myfile.pdf
You can print multiple files at once by listing the file names separated by spaces:
lpr file1.txt file2.txt file3.txt
Print all files in the directory:
lpr -r directory
You can use the lpstat command to view the status of the current print queue:
lpstat -o
Cancel print jobs:
cancel job_number
The cancel command is used to cancel jobs in the print queue, where job_number is the job ID.
If you need more advanced features, refer to the system's man manual:
man lprOther Extensions