lp Command: Tutorial & Examples

Printing files from the shell

The 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.

The 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 operating systems.

How does the lp command work?

The 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 more.

Examples of the lp command

Let's look at some examples of how the lp command can be used:

lp myfile.txt

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.

Typically, the lp command will output the request id of the print job, which can be used to manage the print job with the lpstat or 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, the lpstat command can be used to display the status of print jobs and printers.


The 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 environments.

Except where otherwise noted, content on this site is licensed under a CC BY-SA 4.0 license CC BY SA