lprm - Linux


Overview

The lprm command in Linux is used to remove print jobs from the print queue. It is particularly useful in environments where multiple users share printer resources, allowing users to cancel their own or, with the appropriate permissions, others’ print jobs. This command is essential for managing printer queues to clear out stalled or unwanted jobs.

Syntax

The basic syntax for the lprm command is:

lprm [options] [job-ids]
  • job-ids: Specify the IDs of the print jobs you want to remove. If no job ID is specified, the current job is removed.

Options/Flags

  • -: Removes all jobs; available only to the superuser.
  • -Pprinter: Specifies a particular printer; otherwise, the default printer is used.
  • job-ID: Specifies the job ID to remove from the print queue. Can specify multiple IDs separated by space.
  • username: When run by a superuser, it can remove jobs belonging to a particular user.

Typical use cases:

  • lprm: Removes the current job on the default printer.
  • lprm -: Removes all jobs if you are the superuser.
  • lprm -Pprinter 101: Removes job with ID 101 from the specified printer.

Examples

  1. Remove a Specific Print Job:

    lprm 12345
    

    This command removes the print job with the ID 12345 from the default printer queue.

  2. Remove Multiple Print Jobs:

    lprm 12345 67890 13579
    

    Removes jobs with IDs 12345, 67890, and 13579.

  3. Remove All Jobs from a Specific Printer:

    lprm -Poffice_printer -
    

    This will remove all print jobs from the printer named office_printer.

Common Issues

  • Permission Denied: You may not have the necessary permissions to remove a job. Jobs can typically only be removed by the user who queued them or by a superuser.
  • Invalid Job ID: Ensure that the job ID specified is correct and exists in the print queue.
  • Printer Not Found: The specified printer name might be incorrect. Check the printer name with lpstat -p.

Integration

lprm can be combined with other commands like lpstat for effective management of printer queues. For example:

lpstat -o | grep 'username' | awk '{print $1}' | xargs lprm

This command chain lists all print jobs, filters for those submitted by ‘username’, extracts the job IDs, and removes those jobs.

  • lpstat: Displays information about the current print jobs and printers.
  • lp: Command to queue print jobs.
  • lpr: Another command used to queue print jobs.

Further Reading:

  • The man pages for each command can provide more in-depth information (man lprm, man lpstat, man lp, man lpr).