lpr – Send a file to the specified printer for printing

The lpr command is used to send a file to a printer for printing. It is a command-line utility that allows users to print files from the terminal without the need for a graphical interface.

Overview

The lpr command is used to send a file to a printer for printing. The syntax for the command is as follows:

lpr [options] [filename]

The filename argument specifies the file that needs to be printed. If the filename is not specified, the lpr command will read from standard input.

The lpr command sends the file to the default printer unless a different printer is specified with the -P option. If the -P option is used, the printer name should be specified immediately after the option.

Examples

To print a file named document.txt using the default printer, the following command can be used:

lpr document.txt

To print the same file using a printer named printer1, the following command can be used:

lpr -P printer1 document.txt

The lpr command can also be used to print multiple files at once. For example, to print two files named file1.txt and file2.txt, the following command can be used:

lpr file1.txt file2.txt

Options

The following table lists the available options for the lpr command:

Option Description
-P printer Specifies the printer to use for printing.
-# copies Specifies the number of copies to print.
-C Prints a cover page before the actual file.
-J jobname Specifies the job name to use for the print job.
-U username Specifies the username to use for the print job.
-h Displays help information for the command.

Troubleshooting tips

Here are some common issues that users may encounter when using the lpr command and how to troubleshoot them:

  • The printer is not printing anything: Check that the printer is turned on and connected to the computer. Also, make sure that the printer is not out of paper or ink.
  • The file is not printing correctly: Check that the file is in a format that the printer can handle. Also, make sure that the file is not corrupted or damaged.
  • The printer is printing gibberish characters: Check that the printer is configured correctly and that the correct driver is installed. Also, make sure that the file is in a format that the printer can handle.

Notes

  • The lpr command is part of the CUPS (Common Unix Printing System) printing system, which is used by many Linux distributions.
  • The lpr command is a simple and efficient way to print files from the terminal without the need for a graphical interface.