Previous Table of Contents Next

Module 80
lpq (BSD)


The external lpq command displays the print jobs spooled in the system printer spool queues. To spool a print job you use the lpr command. To remove a job from the spool queue you use the lprm command. For each print job submitted by lpr, lpq displays

*  the user's name
*  the current rank in the spool queue for the given printer
*  the names of the files comprising the job
*  the print job number (you can use this number to remove jobs with lprm)
*  the total number of bytes in the job

Without any options or arguments lpq displays information about all print jobs currently in the queue for all printers. If you specify the -Pprinter option, then only jobs queued to the given printer are displayed. If you provide a job#, then only information pertaining to that job number is displayed. If you provide a username, then only jobs spooled by that user are displayed.


Following is the general format of the lpq command.

     lpq [ +[n] ] [ -l ] [ -Pprinter ] [ job#_list ] [ user_list ]


The following list describes the options and their arguments that may be used to control how lpq functions.

+[n] Displays jobs in the spool (print) queue until the queue is empty. If you supply n, lpq sleeps for n seconds between displays of the queue.
-l Displays information about each print job in the queue. This is multiline output. Normally lpq only displays one line per job. The information is just reformatted on multiple lines.
-Pprinter Displays print jobs related to the specified printer. Overrides the system default printer and the PRINTER environment variable.


The following list describes the arguments that may be passed to the lpq command.

job#_list Display queued job information for the specified jobs. The job numbers must be space separated.
user_list Display queued job information for the specified users. The user names must be space separated.


Because the spool queue is dynamically updated by lpr and lprm the information displayed by lpq may not be accurate. For instance, if another user sends a print job to a printer at the same time you run lpq, you may or may not see the new job spooled to the printer.

The displayed output is padded to accommodate the width of the terminal. Thus exact column positions may change.

If lpq warns that there is no daemon present, contact your system administrator. He will use the lpc command to restart the daemon. @H2=RELATED COMMANDS Refer to the lpr and lprm commands described in modules 81 and 82.


The lpq program uses the following files.

/etc/termcap Contains terminal capabilities used to manipulate the screen during repeated displaying.
/etc/printcap Contains printer characteristics.
/usr/spool/* The spooling directory. May be reset in /etc/printcap.
/usr/spool/printer The directory for a given printer.
/usr/spool/*/cf* Control files for print jobs.
/usr/spool/*/df* Data files for print jobs.
/usr/spool/*/lock Contains the currently active job number.


The lpq command provides a mechanism for viewing the status of a currently queued print job while it is in the system spool queue. You can see how many more print jobs have to be processed before your files are printed. The sizes of each print job is displayed so you can estimate the amount of time for each job to print.


In this activity you use the lpq command to display the spool queue. Begin at the shell prompt.

1.  Type lpr /etc/passwd and press Return. This spools a job for you to display using lpq.
2.  Type lpq and press Return. Notice the output shows the job you spooled in the previous step. You should probably stop by the printer at your next break and clean up all your printouts.
3.  Turn to Module 89 to continue the learning sequence.

Previous Table of Contents Next