lp Command: Tutorial & Examples
Printing files from the shell
lp command is a powerful utility in Linux which allows you to print files directly from
the shell. While it may seem outdated to print files from the command line, it is actually an
efficient way to manage printing tasks, especially when dealing with a large number of files or complex print settings.
lp command sends a print job to a destination, typically a printer. It's a part of the
Common Unix Printing System (CUPS), which is a modular printing system for Unix-like computer
How does the lp command work?
lp command works by sending a request to the CUPS server to print one or more files. The command can be customized
with a variety of options to specify the destination printer, set the number of copies, choose sides for printing, and
Examples of the lp command
Let's look at some examples of how the
lp command can be used:
This command will print the file "myfile.txt" to the default printer.
lp -d myprinter myfile.txt
This command prints "myfile.txt" to the printer named "myprinter".
lp -n 5 myfile.txt
This command prints 5 copies of "myfile.txt" to the default printer.
lp command will output the request id of the print job, which can be used to manage the print job with
cancel commands. For example:
request id is myprinter-8 (1 file(s))
Common problems and solutions
A common issue that may occur when using the
lp command is a network failure. If the
CUPS server cannot reach the printer due to a network issue, the print job will fail. Troubleshooting may involve
checking the network connection and ensuring that the printer is correctly configured in the CUPS server.
Another issue that may arise is when the printer or print job status needs to be checked. For this,
lpstat command can be used to display the status of print jobs and printers.
lp command is a powerful and flexible tool for managing print jobs directly from the command line. While it might
seem a bit old-fashioned, it provides a high degree of control and efficiency that can be a real asset in certain