Cancel the Right CUPS Print Job with lprm
You will finish with a cautious way to cancel one queued CUPS print job, select the intended printer or server, and recognise the command that cancels everything. The examples use lprm from cups-bsd version 2.4.7-1.2ubuntu7.14, installed at /usr/bin/lprm on this machine.
The route
Jump straight to the step you need, or tick off Done means at the end.
Allow about ten minutes. You need a shell, access to the CUPS destination that owns the job, and the job ID. The inspection commands are ordinary user commands. Cancelling a job changes queue state and cannot be undone with lprm, so identify the job before you run the destructive step.
1. Confirm the installed command
Check the binary and package version before relying on option details:
$ command -v lprm
/usr/bin/lprm
$ dpkg-query -W -f='${Package} ${Version}\n' cups-bsd
cups-bsd 2.4.7-1.2ubuntu7.14
Ask the local binary for its option summary as a read-only check:
$ lprm --help
Usage: lprm [options] [id]
lprm [options] -
The useful options are -P for a destination, -h for a server and optional port, -U for a username, and -E to force encryption. The local help confirms the syntax; the installed manpage explains what each option means.
2. List jobs without cancelling anything
Use lpstat -o to inspect queued jobs. This does not call lprm and does not change the queue:
$ lpstat -o
The exact columns and output depend on the CUPS server. Treat the job ID as data to copy exactly, not as a printer name. If the list is empty, there is nothing for this workflow to cancel. If the command reports an error, resolve the destination or server issue first.
Checkpoint: write down three values from the real output: the job ID, the destination, and the server if it is not the local default. Replace the visibly marked placeholders below with those values. Do not copy the sample identifier.
3. Cancel one identified job
For a job on the default destination, pass its numeric or server-issued job ID:
$ lprm JOB_ID
Replace JOB_ID with the value from lpstat -o, for example 1234. The command may print a server response, or it may finish without useful output. A quiet command is not proof that you selected the right queue, so check the queue again:
$ lpstat -o
If the identified job no longer appears, the cancellation was accepted or the job was removed by another process. If it remains, read the diagnostic and confirm that the destination and server match the queue you inspected. Do not repeatedly cancel by guesswork.
There is no undo operation for a cancelled job. If the document is still needed, recover it from its original application or source and submit a new print job after checking the printer problem.
4. Target a particular printer or class
When the same job number could be confused between destinations, include the destination explicitly:
$ lprm -P PRINTER_NAME JOB_ID
Replace PRINTER_NAME with the printer or class name shown by your CUPS configuration. Keep the job ID and destination together from the same queue listing. A class is a CUPS destination that may route work to one of several printers, so verify that cancelling the class job is what you intend.
For a remote CUPS server, add its host and optional port. The -h option must come before the other options:
$ lprm -h PRINT_SERVER:631 -P PRINTER_NAME JOB_ID
Use the server and port recorded by your print setup, not a guessed hostname. If the server uses its default port, the host can be supplied without :631. Re-run the matching queue query against that destination before and after the cancellation if your environment provides it.
5. Keep identity and encryption choices deliberate
-U USERNAME asks the server to use an alternate username:
$ lprm -U PRINT_OWNER -P PRINTER_NAME JOB_ID
Only use this when your CUPS setup expects that identity and you are authorised to act for it. Changing the username can change which jobs the server considers yours; it is not a harmless way to bypass access controls. Do not put passwords into the command line, shell history or this example.
-E forces encryption when connecting to the server. Combine it with the explicit server and destination when the queue contains sensitive documents or the server policy requires encrypted transport:
$ lprm -E -h PRINT_SERVER:631 -P PRINTER_NAME JOB_ID
Encryption protects the connection; it does not select the correct job and does not grant permission to cancel it. Elevated privileges are not a normal prerequisite. Running sudo lprm ... changes the local identity presented by the client and can select a different set of jobs, so use it only when the print service administrator has explicitly defined that workflow.
6. Avoid the two easy cancellation traps
With no arguments, lprm cancels the current job on the default destination:
$ lprm
This is not a harmless status check. It is appropriate only when you have already confirmed what the default destination's current job is and deliberately want to remove it.
A single hyphen cancels all jobs:
$ lprm -
That is a destructive, service-disrupting action. It can affect other users and every queued job visible through the selected server and destination. Do not use it as a shortcut for finding your own stuck job. There is no batch undo; recovering requires resubmitting each document that was needed.
7. Diagnose a failed cancellation
First compare the command with the queue listing. Check the spelling of the destination, the job ID, and the server, then inspect the queue again:
$ lpstat -o -P PRINTER_NAME
$ lprm -P PRINTER_NAME JOB_ID
$ lpstat -o -P PRINTER_NAME
If the job belongs to another user or the server rejects the request, do not switch to -U or sudo until you have confirmed the access policy. Ask the print administrator to remove a job when your account is not authorised. If the job disappeared between the two checks, another client or the printer scheduler may have processed it.
For a remote queue, repeat the operation with the exact -h value used to inspect it. The -h option must be first, so this is valid:
$ lprm -h PRINT_SERVER:PORT -P PRINTER_NAME JOB_ID
Do not treat a successful command as proof that the printer stopped immediately. Cancellation applies to the queued job; a printer may already have received or started the document before the server accepted the request. If the output has reached the device, use the printer's documented local controls and follow the site's safety procedure.
Done means
- You confirmed the local
lprmbinary andcups-bsdversion. - You found the real job ID and destination with a read-only queue listing.
- You used an explicit destination or server when the default was ambiguous.
- You checked the queue after cancelling and understood that no undo command exists.
- You did not confuse no arguments with a status check or
-with one-job cancellation. - You used an alternate username, encryption or elevated privilege only when the print service policy required it.