-->
Previous Table of Contents Next


All these commands have man pages, which you should consult for more information. The important points are that by default, lpr, lprm, lpc, and lpq operate on a printer called lp. If you define an environment variable called PRINTER, the name defined is used instead. You can override lp and the PRINTER environment variable by specifying the printer name to use on the command line like so:


lpc -PMYPRINTER

The lpd Daemon

Linux handles all print jobs via the lpd daemon. If this process isn’t running, no printing can take place; print files will remain in their spool directories until the lpd process is started (more information about spool directories appears later in the section “Understanding the Important Directories”).


See “Understanding Processes,” p. 349

If your system doesn’t load lpd at startup, or if for some reason you must kill and then restart the lpd daemon, the following command starts the printer daemon:


lpd [options]

The man page on lpd gives a list of options, but one important option when configuring your Linux printers is -l, which creates a log file that logs each print request to the system. This log file can be useful when you’re debugging your printing system.

The lpr Command

The lpr command submits a job to the printer, or queues a print job. What actually happens is that the file you specify is copied to the spool directory. Each printer specified for your Linux system must have its own spool directory. The size of this spool directory is specified in the minfree file located in each directory. The minfree file specifies the number of disk blocks to reserve for spooling files to the printer. This is done to keep the lpd daemon from using up the entire hard drive when spooling a print request.

lpd finds the file, which then takes care of moving the data to the physical printer. If you don’t specify a file, lpr uses standard input.

The lpq Command

The lpq command shows you the contents of the spool directory for a given printer. One important piece of information displayed by lpq is the job ID, which identifies a particular job. This number must be specified if you want to cancel a pending job.

lpq also indicates with a number a rank for each job in the queue (meaning, where the job is in the queue). active means the file is actually printing—or at least that lpd is trying to print it.

The lprm Command

The lprm command removes a job from the queue—that is, it removes unprinted files from the spool directory. You can specify a job ID (obtained by using the lpq command), or you can specify - as the job ID to cancel all jobs belonging to you.

If you issue lpq - as root, all jobs for the printer are canceled. If you are root and want to remove all the jobs belonging to a specific user, specify the user’s name.

The lpc Command

The lpc command lets you check the status of printers and control some aspects of their use. In particular, lpc lets you start and stop despooling on printers, enable or disable printers, and rearrange the order of jobs in a print queue. The following commands disable printing on myprinter, enable the spool queue on yourprinter, and move job number 37 to the top of the queue:


lpc down myprinter

lpc enable yourprinter

lpc topq 37

If you invoke lpc without any command arguments, lpc is interactive, prompting you for actions to take. Some of the more important commands are shown in Table 20.2; read the man page for complete instructions. Most lpc commands take the name of the printer, as specified in /etc/printcap, as the parameter.

Table 20.2 Some Common lpc Commands

Command Parameter Description

stop printer Stops the printer, but print requests are still spooled.
start printer Allows the printer to start printing previously spooled files and any new files spooled to this printer.
exit, quit (None) Leaves lpc interactive mode.
status printer Displays the current status of the printer. status provides such information as whether the queue is enabled, whether the printer is enabled, and the number (if any) of jobs now in the queue waiting to be printed.


NOTE:  Bear in mind that some lpc commands are restricted to root—that is, the superuser.


CAUTION:  
lpc is very unstable in its current implementation under Linux. Some users have reported that lpc can display incorrect status messages and sometimes even hang the system outright.

Understanding the Important Directories

There’s only one important directory in printing—the spool area where data to be printed is accumulated before /etc/lpd prints it. However, a system is typically set up with multiple spool directories, one for each printer, to make printer management easier. For example, my system is set up to use /usr/spool/lpd as the main spool area, with each separate printer having a directory under that with the same name as the printer. Thus, a printer named ps_nff has /usr/spool/lpd/ps_nff as its spool directory.

The spool directories should belong to the daemon group and should be user and group read/writable and world readable—that is, after you create the directory, make sure that it has the permissions -rwxrwxr-x (0775) with the chmod command. For the directory myprinter, the appropriate command is this:


chmod ug=rwx,o=rx myprinter

chgrp daemon myprinter


See “File Permissions,” p. 310


NOTE:  The locations, ownerships, and permissions given here are a simplification and may be incorrect for your system, so you should take notes on the lpd files and permissions.


Previous Table of Contents Next