LinuxCommandLibrary

lp

Print files

TLDR

Print the output of a command to the default printer (see lpstat command)

$ echo "test" | lp
copy

Print a file to the default printer
$ lp [path/to/filename]
copy

Print a file to a named printer (see lpstat command)
$ lp -d [printer_name] [path/to/filename]
copy

Print n copies of a file to the default printer
$ lp -n [n] [path/to/filename]
copy

Print only certain pages to the default printer (print pages 1, 3-5, and 16)
$ lp -P 1,3-5,16 [path/to/filename]
copy

Resume printing a job
$ lp -i [job_id] -H resume
copy

SYNOPSIS

lp [options] [file(s)]
lp -i job-id [options]

PARAMETERS

-d destination
    Specifies the printer or class to print to. If not specified, the system default printer or the one defined by the LPDEST or PRINTER environment variables is used.

-n copies
    Sets the number of copies to print for each file.

-o option=value
    Specifies one or more printer-specific options. Common options include media=A4, landscape, portrait, sides=two-sided-long-edge, fit-to-page, page-ranges=1-5,7.

-t title
    Sets the title of the print job, which may appear in printer queues or headers.

-q priority
    Sets the priority of the print job from 1 (lowest) to 100 (highest).

-h hostname[:port]
    Specifies the CUPS server to connect to.

-i job-id
    Used to modify or re-print an existing job. This option is typically used with other options like -n or -o to change job properties.

-P page-list
    Prints only the specified pages. Example: 1-5,9,12-.

-s
    Suppresses the 'request id is...' message upon successful job submission.

-U username
    Specifies the username for the print job if different from the current user.

DESCRIPTION

The lp command is used to submit print jobs to a designated printer or to the system's default printer. It is the primary command-line interface for printing files on systems utilizing the CUPS (Common Unix Printing System) backend, as well as historically for System V printing systems.

When invoked, lp sends the specified file(s) or standard input to the print spooler, which then manages the printing process. It allows users to control various aspects of the print job, such as the target printer, number of copies, page ranges, and specific printer options like paper size, orientation, and duplex printing, by using various command-line options. Upon successful submission, lp usually returns a job ID, which can be used to monitor or cancel the print job. It provides a flexible and powerful way to integrate printing into shell scripts and automated workflows.

CAVEATS

The exact behavior and available options of lp can vary slightly depending on the underlying printing system (CUPS vs. traditional System V). Modern Linux distributions predominantly use CUPS.

Printer options specified with -o are printer-specific; not all printers support all options. Refer to your printer's documentation or use lpoptions -l printername to see supported options.

Permissions are crucial. Users must have appropriate permissions to submit jobs to a printer.

Jobs submitted using lp are typically spooled locally before being sent to the printer. Ensure sufficient disk space for large jobs.

DEFAULT PRINTER

The lp command will use the default printer if no destination is specified with -d. The default printer can be set using the LPDEST or PRINTER environment variables, or configured system-wide.

STANDARD INPUT

If no file argument is provided, lp reads data from standard input. This is useful for piping output from other commands directly to the printer, e.g., ls -l | lp.

HISTORY

The lp command has a long history in Unix-like operating systems, originating from the AT&T System V Unix printing system. It traditionally served as the counterpart to the BSD lpr command. With the advent of CUPS (Common Unix Printing System) in the late 1990s, lp (along with lpr, lpq, lprm, etc.) was reimplemented to interface with the CUPS daemon. On most modern Linux distributions, lp directly communicates with CUPS, providing a unified and standardized printing interface that combines features from both System V and BSD printing traditions, while adding robust network printing capabilities. Its widespread adoption ensures backward compatibility while leveraging modern printing infrastructure.

SEE ALSO

lpr(1), lpq(1), lpstat(1), cancel(1), lpoptions(1), cupsd(8)

Copied to clipboard