lpr

system administrationLinux/Unix
The lpr command is one of the most frequently used commands in Linux/Unix-like operating systems. lpr Print files

Quick Reference

Command Name:

lpr

Category:

system administration

Platform:

Linux/Unix

Basic Usage:

lpr [options] [arguments]

Common Use Cases

    Syntax

    lpr [options] [file...]

    Options

    Option Description
    -# num Print num copies
    -C class Job classification for banner page
    -h Suppress printing of banner page
    -J name Job name for banner page
    -m Send email when job is complete
    -o option Specify printer-specific options (CUPS)
    -P printer Send output to the specified printer
    -r Remove files after printing
    -T title Title for pr (when used with -p)
    -p Format with pr before printing
    -l Raw print (no filtering or post-processing)
    -U username Print as the specified user
    -q Quiet mode

    Examples

    How to Use These Examples

    The examples below show common ways to use the lpr command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.

    # Basic Examples Basic
    lpr document.txt
    Print document.txt using the default printer.
    lpr -P laser document.txt
    Print document.txt using the printer named "laser".
    # Advanced Examples Advanced
    lpr -#3 document.txt Print 3 copies of document.txt. lpr -h document.txt Suppress the printing of the banner page. lpr -r document.txt Delete the file after printing it.
    cat file.txt | lpr
    Print file.txt from standard input. ls -la | lpr -P laser Print the directory listing on the printer named "laser". lpr -m document.txt Send an email notification when the job completes. lpr -o landscape document.txt Print in landscape orientation (using CUPS options). lpr -J "Quarterly Report" report.pdf Set the job name to "Quarterly Report" for easier identification in the queue.

    Try It Yourself

    Practice makes perfect! The best way to learn is by trying these examples on your own system with real files.

    Understanding Syntax

    Pay attention to the syntax coloring: commands, options, and file paths are highlighted differently.

    Notes

    The 'lpr' (line printer) command is a standard Unix/Linux utility for sending files to a printer. It's one of the core components of the printing system and has been a part of Unix-like operating systems for decades. Key features of the lpr command: 1. Universal Print Interface: lpr provides a consistent command-line interface for printing across different Unix/Linux distributions, allowing users and scripts to print documents without needing to know the details of the underlying print system. 2. Multiple Print Systems Support: The lpr command is implemented in both the Berkeley LPD (Line Printer Daemon) printing system and the newer CUPS (Common Unix Printing System), making it broadly compatible across systems. 3. Queue Management: lpr adds print jobs to a spooling queue, allowing the system to manage multiple print requests efficiently and enabling printing even when printers are busy or offline. 4. Flexible Input Handling: The command can print files specified on the command line or accept input from standard input (via pipes or redirection), making it easy to integrate with other commands and scripts. 5. Print Job Customization: Through various options, lpr allows customization of print jobs, including specifying the printer, number of copies, job identification, and in CUPS implementations, more advanced options like paper size or orientation. 6. User Notifications: Options like '-m' enable email notifications when jobs complete, which is useful for long print jobs or busy environments. 7. Batch Processing: The ability to specify multiple files in a single command makes it convenient for batch printing. The lpr command is typically used in these scenarios: - Command-line printing of documents - Scripted/automated printing tasks - Printing output from other commands (via pipes) - Integration with text processing workflows - System administration tasks related to printing In modern Linux distributions using CUPS, lpr includes extended functionality through the '-o' option, which allows setting CUPS-specific options like paper size, media type, resolution, and many other printer-specific settings. It's worth noting that while lpr is primarily a command-line tool, its functionality is often exposed through graphical printing dialogs in desktop environments, providing users with a more accessible interface while using the same underlying printing system.

    Related Commands

    These commands are frequently used alongside lpr or serve similar purposes:

    Use Cases

    Learn By Doing

    The best way to learn Linux commands is by practicing. Try out these examples in your terminal to build muscle memory and understand how the lpr command works in different scenarios.

    $ lpr
    View All Commands