How to Clear the Print Queue in Linux using the cancel Command

Managing the Print Spooler

In a Linux environment, whether you are managing a desktop workstation or a dedicated CUPS (Common UNIX Printing System) print server, print jobs occasionally become corrupted. If a user accidentally sends a massive 500-page PDF to a printer that has run out of paper, the print job will hang indefinitely in the spooler queue. Any subsequent print jobs sent by other users will simply stack up behind the broken job, effectively taking the printer offline.

To resolve this, you must interact with the CUPS daemon via the terminal and forcefully delete the corrupted jobs from the queue.

Step 1: View the Active Print Queue

Before you delete anything, you should verify exactly what is stuck in the queue. You can list all pending print jobs using the lpstat command.

Open your terminal and run:

lpstat -p -d

This will show you the status of all configured printers. To see the actual queue of jobs, run:

lpq

The output will look something like this:

HP_LaserJet_Pro is ready
Rank    Owner   Job     File(s)                         Total Size
active  john    14      financial_report.pdf            409600 bytes
1st     sarah   15      marketing_flyer.jpg             1024000 bytes

Take note of the Job ID number. In this example, the stuck job blocking the queue is Job 14.

Step 2: Cancel a Specific Job

To delete a single, specific print job while leaving the rest of the queue intact, use the cancel command followed by the Job ID.

cancel 14

The command executes silently. If you run lpq again, you will see that Job 14 has vanished, and Sarah’s marketing flyer has automatically begun printing.

Step 3: The Nuclear Option (Clear All Jobs)

If the printer queue has completely melted down and there are dozens of failed jobs stacked up, deleting them one by one is inefficient. You can force the CUPS daemon to instantly purge every single job for every single user.

To wipe the entire queue clean, use the cancel command with the -a (all) flag.

cancel -a

Note: If you only want to clear the queue for a specific printer (perhaps leaving the marketing team’s plotter printer alone), you can specify the printer name after the flag.

cancel -a HP_LaserJet_Pro

What if the Command Fails?

Occasionally, a print job becomes so deeply corrupted that the CUPS daemon cannot delete it, and the cancel command will return an error or simply hang.

In this extreme scenario, you must stop the printing service entirely, manually delete the raw spool files from the hard drive, and restart the service.

sudo systemctl stop cups
sudo rm -rf /var/spool/cups/*
sudo systemctl start cups

This bypasses the CUPS software entirely, physically destroying the spooled files and guaranteeing a completely fresh start for the print server.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.