
- Unix Commands Reference
- Unix Commands - Home
cancel Command in Linux
The cancel command in Linux serves a single, specific purpose: to manage print jobs. It allows you to stop printing tasks that have been sent to a printer, either locally or on a print server. Users can cancel and help you halt printing processes that are currently underway. The cancel command in Linux is specifically used for managing print jobs.
Table of Contents
- Understanding cancel Command in Linux
- Install cancel Command in Linux
- How to use cancel Command in Linux?
- Alternatives of cancel Command in Linux
Understanding cancel Command in Linux
This is useful in various scenarios, for example,
- Accidentally sending the wrong document to print,
- Needing the printer for another job urgently,
- Simply wanting to free up space in the print queue
- A long print job is taking too long and you need the printer for something else.
- You want to delete any leftover data files associated with canceled jobs.
Install cancel Command in Linux
The cancel command for managing print jobs typically comes pre-installed on most Linux distributions. It's a standard utility included in the lpr package (line printer remote).
Therefore, you usually don't need to install it separately. You can verify its existence by opening a terminal and typing −
cancel --help
If cancel is installed, this will display the help message explaining its usage and options.
In the rare case where cancel is missing, you'd likely need to install the lpr package using your distribution's package manager.
Here are some common installations −
Debian / Ubuntu
sudo apt install lpr
Red Hat / CentOS / Fedora
sudo yum install lpr
Once the lpr package is installed, the cancel command should be available for use.
How to use cancel Command in Linux?
The cancel command allows you to cancel existing print jobs on a print server or locally. To cancel print jobs that have been sent to a printer. You can cancel all jobs, jobs owned by a specific user, or jobs destined for a particular printer.
The basic syntax for using cancel is −
cancel [options] [job_number]
In the above syntax,
- options − These are the flags mentioned above (e.g., -a, -u username).
- job_number − This is optional and allows you to cancel a specific print job by its job number (obtained through the lpq command).
Let’s explain the different options you can use with the cancel command −
Options | Descriptions |
---|---|
-a | This option cancels all print jobs. If you don't specify a destination printer, it cancels jobs on all printers. |
-E | Force encryption when connecting to the print server for secure communication. |
-h hostname[:port] | Use a different server for printing. You can optionally specify the port number after the hostname. |
-U username | Provide a specific username for authentication on the print server. |
-u username | Cancel print jobs that are owned by the specified username. |
-x | In addition to canceling jobs, this option also deletes the associated job data files on the server. |
Here are some examples showcasing various functionalities of the cancel command −
Cancel all Jobs on the Default Printer
This is the simplest scenario where you want to clear all printing tasks from the queue. This option cancels all print jobs on the specified destination (printer) or all destinations if no printer is specified.
cancel -a
Cancel Jobs Destined for a Specific Printer
Let's say you have a printer named "laserjet" and want to cancel all jobs going to it.
cancel -a laserjet
Cancel a Job Owned by a Particular User
If John accidentally sent a document to print and you want to stop it, use his username. This cancels print jobs that are owned by the username you provide −
cancel -u john
Cancel a Specific Job by Its ID and Delete Its Data File
You can check the print queue using lpq and find the job ID. Here, we cancel job 123 and remove its data. This option, in addition to canceling jobs, also deletes the job data files associated with them on the print server −
cancel -x 123
Cancel Jobs While using a Different Print Server
Imagine you have a backup server named "server2" for printing. You can cancel jobs there −
cancel -h server2
Cancel Jobs While Forcing Encryption with the Print Server
For increased security during communication, use the -E flag. This forces encryption when connecting to the print server. This adds an extra layer of security during communication −
cancel -E # Can be combined with other options like -a or -u username
Specifying a Port Number for the Alternate Print Server
If your alternate server (e.g., "backup") uses a non-standard port (say, 631), specify it. This allows you to specify an alternate print server. You can optionally include the port number after the hostname −
cancel -h backup:631
Combining Options for a Specific Scenario
Suppose you want to cancel all jobs on "server2" while using encryption and deleting data files −
cancel -Ex server2
Replace "laserjet", "john", "server2", and "123" with your actual usernames, printer names, and job IDs.
Consult your system's documentation for detailed information about cancel and its behavior on your specific Linux distribution.
Alternatives of cancel Command in Linux
In the context of managing print jobs on Linux, there isn't a direct alternative to the cancel command itself. It's the primary tool for this specific task.
However, depending on your situation, here are some approaches that might achieve similar results −
Graphical User Interface (GUI)
Most Linux distributions come with a graphical print queue manager. You can usually access it through your system settings or directly from the print dialog when selecting a printer for a document. This interface often provides a user-friendly way to view and cancel print jobs.
Stopping the Print Spooler Service
This is a more drastic approach. The print spooler service manages the print queue and processes jobs. Stopping it will effectively halt all printing activity, including any ongoing jobs. However, this is not recommended for regular use as it can disrupt printing functionality and might require restarting the service to resume printing later.
Pausing and Resuming Jobs (if Supported)
Some print queue managers might offer the option to pause a print job. This would temporarily stop the printing process and allow you to resume it later if needed. While not technically canceling, it achieves a similar outcome of temporarily stopping a print job.
Conclusion
In Linux, cancel only works with print jobs. It cannot cancel other types of running programs or processes. Using "cancel -x" might be necessary if the print server accumulates data files for each job. Deleting them frees up space.
To cancel all jobs on the default printer: "cancel -a". To cancel a job owned by the user "john": cancel -u john. To cancel job number 123 and delete its data file: cancel -x 123
Always consult your system's documentation for specific details about cancel and its behavior on your particular Linux distribution.