Running Linux, 5th Edition - Matthias Kalle Dalheimer [269]
$ lprm 442
The spooled print file identified as job 442 is discarded. You can narrow the lpq report by asking about a specific print job by task ID (rarely used), by printer, or by user ID. For example, to get a report that identifies spooled files sent to a printer named hp4500, you would enter
$ lpq hp4500
ada is ready and printing
Rank Owner Job File(s) Total Size
active lovelac 788 (stdin) 16713 bytes
1st lark 796 (stdin) 70750 bytes
If you are the root user, you can kill all pending printing tasks by entering the command:
# lprm -
If you are not the root user, issuing that command kills only the printing tasks you own. This restriction also holds true if you specify a printer:
# lprm ada
If you are root, the print queue is emptied. If you are a normal user, only the print files you own are removed from the specified print spool. The lprm utility reports on the tasks it kills.
The root user can kill all the print tasks issued by any user by specifying:
# lprmusername
If you issue lprm with no argument, it deletes the currently active print jobs that you own. This is equivalent to entering:
$ lprmyourusername
If you want to see whether a queue is down, you can use the lpc command:
$ /usr/sbin/lpc status epson_360
See "Managing Print Services" for details. The lpc utility is usually installed in the /sbin or /usr/sbin directory. Alternatively, the CUPS lpstat command performs a task similar to lpc status.
Some Common Command-Line Printing Tasks
Sometimes you want to do more than just send a file that's already been prepared for printing to the printer. For instance, you might want to print a manpage or some other document that's not quite ready for printing. To do so, you can use various Linux utilities, often in pipelines, to do the job. For instance, to get a quick hardcopy printout of the cupsd manual page, enter:
$ man cupsd | col -b | lpr
The man command finds, formats, and outputs the cupsd manual page in an enriched ASCII output that uses backspaces to overstrike and underline characters (in place of italics) for highlighting. The output is piped through col, a Unix text filter, whose -b option strips the backspace instructions embedded in the manpage, which results in simple text strings while maintaining the layout of the formatted manpage. The output of col is piped to lpr, which spools the text in a spool directory.
Suppose you want to print the fully enriched manpage with highlighting and all. You might use a command like this:
$ gunzip -c /usr/share/man/man8/cupsd.8.gz | groff -man -Tps | lpr
The gunzip -c command uncompresses the compressed manpage and passes the results to standard output (and hence to the next command in the pipeline). The groff command applies the man macros to the file specified, creating PostScript output (specified by -Tps). This output is then passed to lpr, which spools it, and CUPS applies the default print-processing instructions for the default print queue.
Another useful tool for printing pure-text files is the pr command, which formats files in a number of ways. For instance, you can create multicolumn output, documents with headers, numbered lines, and more. Consult the pr manpage for details.
Most Linux distributions today use CUPS as the default printing system, but older distributions used the LPRng system or the even older BSD LPD system. (Some distributions ship with two or all three of these systems, but CUPS is usually the default choice.) The BSD LPD and LPRng systems use commands similar to those described here, so even if your distribution uses these older systems, you should be able to use these commands. Some Unix printing systems, such as the SysV printing system, use different commands, such as lp for printing. If you've installed such an unusual (for Linux) printing system, you may need to look at its documentation to learn how it works.
* * *
Tip
CUPS was designed as a drop-in replacement for LPD systems such as BSD LPD and LPRng, as well as for SysV-style