lp Command Examples

lp is a command-line utility used for printing files on Unix-like operating systems. It serves as a simple interface for sending print jobs to printers connected to the system or accessible over a network. The lp command provides users with a convenient way to initiate printing tasks from the command line without requiring interaction with a graphical user interface.

Key features and functionalities of the lp command include:

  • File Printing: lp allows users to print one or more files by specifying their filenames or paths as command-line arguments. Users can initiate printing of text files, documents, images, PDFs, and other printable file formats directly from the terminal.
  • Print Queue Management: lp manages a print queue that stores print jobs awaiting processing by the printer. Users can view the status of print jobs in the queue, prioritize or cancel specific print jobs, and manage the order in which print jobs are processed.
  • Printer Configuration: lp supports configuration options for specifying printer settings, such as paper size, orientation, color mode, print quality, and number of copies. Users can customize these settings according to their printing requirements before sending the print job to the printer.
  • Printer Selection: lp allows users to specify the printer destination for the print job, especially in systems with multiple printers installed or network printers accessible over the network. Users can select the target printer by its name, queue identifier, or network address.
  • Print Job Monitoring: lp provides options for monitoring the progress and status of print jobs, including information such as job ID, job status, printer status, and completion time. Users can use these options to track the progress of their print jobs and troubleshoot any issues that may arise during printing.
  • Integration with Spooling Systems: lp integrates with spooling systems such as CUPS (Common Unix Printing System) to manage the printing process efficiently. It leverages the capabilities of the underlying spooling system to handle print job scheduling, queuing, and communication with printers.
  • Scripting and Automation: lp can be used in shell scripts and automated workflows to perform printing tasks programmatically. This allows users to automate repetitive printing tasks, generate printouts from batch processes, or incorporate printing into larger workflows and processes.
  • Cross-Platform Compatibility: lp is available on various Unix-like operating systems, including Linux, macOS, and BSD distributions. It provides consistent printing capabilities across different platforms, allowing users to leverage its features regardless of the underlying operating system.

lp Command Examples

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

# echo "test" | lp

2. Print a file to the default printer:

# lp [path/to/filename]

3. Print a file to a named printer (see lpstat command):

# lp -d [printer_name] [path/to/filename]

4. Print N copies of file to default printer (replace N with desired number of copies):

# lp -n [N] [path/to/filename]

5. Print only certain pages to the default printer (print pages 1, 3-5, and 16):

# lp -P 1,3-5,16 [path/to/filename]

6. Resume printing a job:

# lp -i [job_id] -H resume

Summary

In summary, lp is a versatile and efficient command-line utility for printing files on Unix-like systems. With its support for file printing, print queue management, printer configuration, printer selection, print job monitoring, integration with spooling systems, scripting capabilities, and cross-platform compatibility, lp provides users with a convenient and flexible solution for initiating and managing printing tasks from the command line.

Related Post