How to Use the Lp Command in Linux to Print Files
The lp
command in Linux is a powerful tool for printing files, offering a wide range of options to customize the printing process. This article will guide you through the various ways to use the lp
command, including how to specify printers, set printing options, and manage print jobs.
Basic Usage of the Lp Command
The lp
command is used to submit files for printing or to alter a pending print job. Here is a basic example of how to use it:
lp filename
This command will print the specified file to the default printer. If you want to print from standard input, you can use a dash (-
) as the filename:
lp -
This will allow you to pipe output from another command to the printer.
Specifying the Printer
To print to a specific printer, you can use the -d
option followed by the name of the printer:
lp -d myprinter filename
This command will print the file filename
to the printer named myprinter
.
Setting Printing Options
The lp
command supports a variety of options to customize the printing process. Here are some common options:
-
Media Size: You can specify the media size using the
-o media=size
option. For example:lp -d myprinter -o media=legal filename
This will print the file on legal-sized paper.
-
Orientation: To print in landscape orientation, use the
-o landscape
option:lp -d myprinter -o landscape filename
This will rotate the print job by 90 degrees.
-
Sides: To print on both sides of the paper, use the
-o sides=two-sided-long-edge
or-o sides=two-sided-short-edge
option:
lp -d myprinter -o sides=two-sided-long-edge filename
This is typically used for portrait (unrotated) pages.
-
Scaling: To scale the print file to fit on the page, use the
-o fit-to-page
option:lp -d myprinter -o fit-to-page filename
This ensures that the content is adjusted to fit within the page boundaries.
-
Multiple Pages per Sheet: You can print multiple document pages on each output page using the
-o number-up=N
option:lp -d myprinter -o number-up=4 filename
This will print four document pages on each output page.
-
Text File Options: For text files, you can set the characters per inch (cpi) and lines per inch (lpi) using the
-o cpi=N
and-o lpi=N
options, respectively. You can also set page margins:
lp -d myprinter -o cpi=12 -o lpi=8 -o page-left=72 filename
This sets 12 characters per inch, 8 lines per inch, and a 1-inch left margin.
Managing Print Jobs
The lp
command also allows you to manage pending print jobs. Here are some useful options:
-
Job ID: To specify an existing job to modify, use the
-i job-id
option:lp -i job-id -m filename
This will modify the specified job and send an email when the job is completed.
-
Priority: You can set the job priority using the
-q priority
option:lp -d myprinter -q 50 filename
The priority ranges from 1 (lowest) to 100 (highest), with 50 being the default.
-
Hold and Resume: To hold a job indefinitely, use the
-o hold
option:
lp -d myprinter -o hold filename
To resume a held job, use the -i job-id
and -o resume
options:
lp -i job-id -o resume
This will resume the specified job.
Listing Available Printers and Print Queues
To see a list of available printers, you can use the lpstat
command:
lpstat -p -d
This will display a list of printers and the current default printer.
Advanced Options and Customization
For more advanced customization, you can use the lpoptions
command to set default options for a printer. For example:
lpoptions -d myprinter -o media=legal
This sets the default media size for the myprinter
printer to legal size.
You can also list the available options for a printer using:
lpoptions -p myprinter -l
This will display the supported options for the specified printer.
By leveraging these options and commands, you can effectively manage and customize your printing tasks in Linux using the lp
command.