📄 lsg19.htm
字号:
<BR>
<P>Linux systems control printers through a utility called lpc. The lpc program enables you to do several important functions involving the printers on your Linux system:
<BR>
<UL>
<LI>Display printer status information
<BR>
<BR>
<LI>Enable or disable the printer
<BR>
<BR>
<LI>Enable or disable the printer queue
<BR>
<BR>
<LI>Remove all print requests from a printer's queue
<BR>
<BR>
<LI>Promote a particular print request to the top of the queue
<BR>
<BR>
<LI>Make changes to the lpd daemon
<BR>
<BR>
</UL>
<P>You cannot use the lpc program for remote printers. It only affects those printers directly attached and configured on the local machine. If you must manage a remote printer, log into the remote machine as root and make the changes through that login.
<BR>
<BLOCKQUOTE>
<BLOCKQUOTE>
<HR ALIGN=CENTER>
<BR>
<NOTE>The lpc utility is one of the most unpredictable and unreliable programs included with the Linux operating system. It can hang up for no obvious reason and can display faulty status messages.</NOTE>
<BR>
<HR ALIGN=CENTER>
</BLOCKQUOTE></BLOCKQUOTE>
<P>When executed on the command line without any arguments, lpc prompts you for a command. The following list summarizes all the valid lpc commands and their arguments (a vertical bar indicates a choice of arguments):
<BR>
<UL>
<LI>abort <I>printer_name</I> | all This command is similar to the stop command except that it doesn't allow a print job that is currently being printed to finish before stopping the printer. When you use it with the all argument, all printers are stopped. Any job that is terminated by the abort command is requeued when the printer is restarted.
<BR>
<BR>
<LI>clean <I>printer_name</I> | all This command removes all print jobs that are queued, including any active print jobs. (In many cases, the currently printing job proceeds normally because it already has been passed to the printer daemon or the printer's RAM buffer and can't be stopped by lpc.) If you use the all argument, all printers have their print queues removed.
<BR>
<BR>
<LI>disable <I>printer_name</I> | all This command disables the spooling of print requests to the printer (or all printers, depending on the argument). Any jobs that are already queued are unaffected. Any user trying to send a print job to a disabled printer receives a message indicating that the printer is disabled and the print job is refused. Printers are enabled and disabled through changes in the lock file in the spool directory.
<BR>
<BR>
<LI>down <I>printer_name</I> <I>message</I> This command is used to take a printer off-line (usually for extended periods). You can include a message of any length as well. This message is placed in the status file in the spool directory and is displayed to users trying to queue to the printer. Use the down command when a printer has serious problems and must be removed from the system.
<BR>
<BR>
<LI>enable <I>printer_name</I> | all This command enables the spooling of print requests to the printer (or all printers) after a halt.
<BR>
<BR>
<LI>exit This command exits from lpc (the same as quit).
<BR>
<BR>
<LI>help or ? This command shows a short list of all lpc commands. If you type in an lpc command after the help command, the system displays a one-line description of the command you typed.
<BR>
<BR>
<LI>quit This command exits from lpc (the same as exit).
<BR>
<BR>
<LI>restart <I>printer_name</I> | all This command restarts the printer daemon. This command is usually used after the daemon has died for an inexplicable reason. If you supply the all argument is supplied, all printer daemons are restarted.
<BR>
<BR>
<LI>start <I>printer_name</I> The command starts the printer queue daemon for the printer you specify, allowing it to print requests.
<BR>
<BR>
<LI>status <I>printer_name</I> This command displays the printer name, whether it has the spool queue enabled, whether printing is enabled, the number of entries in the print queue, and the status of the daemon for that printer. If no entries are in the queue, there will be no printer daemon active. However, if there are entries in the queue and the printer daemon shows as no daemon present, then the daemon has died and must be started again with the restart command.
<BR>
<BR>
<LI>stop <I>printer_name</I> This command stops the printer. Print requests can still be spooled, but they are not printed until the printer is started. If a job is being printed when you issue the stop command, the printer stops after it completes the job. The start and stop commands alter the contents of the lock file in the print spool directory. The stop command also kills the daemon for spooling to that printer.
<BR>
<BR>
<LI>topq <I>printer_name</I> <I>print_ID</I> This command moves the print request with <I>print_ID</I> to the top of the print queue.
<BR>
<BR>
<LI>topq <I>printer_name</I> <I>username</I> This command moves all print requests owned by <I>username</I> to the top of the queue.
<BR>
<BR>
<LI>up <I>printer_name</I> This command reactivates a printer that was taken down. See the down command for more information.
<BR>
<BR>
</UL>
<P>The lpc utility is not very user-friendly, but it is the only way to handle the printers and their queues in Linux. Several front-end menu-driven utilities are beginning to appear that simplify this task, but they are of variable quality and are not widely available.
<BR>
<BR>
<A NAME="E68E106"></A>
<H3 ALIGN=CENTER>
<CENTER>
<FONT SIZE=5 COLOR="#FF0000"><B>Managing the Printer Queue with lpq and lprm</B></FONT></CENTER></H3>
<BR>
<P>Instead of totally relying on the lpc command, you can use the several commands that help you administer the printer queue directly. These commands are designed to simplify the two tasks that are commonly required by a system administrator: displaying the current queue and removing print jobs in a queue.
<BR>
<P>To display the current print queue for any printer, use the lpq command. It has the following syntax:
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">lpq [-l] [-Pprinter_name] [job_ID ...] [username ...]</FONT></PRE>
<P>With no arguments, lpq displays information about the current printer queues. The lpq command normally displays information about who queued the print job, where it is in the queue, the files being printed, and the total size of the files. The -l option displays more information about each entry in the printer queue. Usually only one line of information is displayed.
<BR>
<P>You can display a specific printer with the -P option followed by the printer's name. If no name is supplied, the default system printer is displayed. If one or more job_IDs or usernames are provided, only information about the specified jobs or jobs queued by the specified user is shown.
<BR>
<P>To remove files from a printer queue, use the lprm command. This command is often mistyped as lpr, which does not remove the file from the queue. To use lprm, you must know the print job ID, or, if you are logged in as root, you can remove all jobs for a particular printer. The syntax of the lprm command is as follows:
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">lprm [-Pprinter_name] [-] [job_ID ...] [username ...]</FONT></PRE>
<P>If the single hyphen argument is used, lprm removes all jobs owned by the user who issues the command. If you are logged in as root and issue this command, all print jobs are removed.
<BR>
<P>You can remove a particular printer's jobs by using the -P option. For example, the command
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">lprm -Phplj -</FONT></PRE>
<P>removes all print jobs queued on the printer hplj by the user who issues the command or all print jobs for that printer if the command is issued by root. If a print job ID or a username is supplied as an argument, lprm removes the specified job or all jobs submitted by the specified user. If no arguments are supplied, the currently active job submitted by the user is deleted.
<BR>
<BLOCKQUOTE>
<BLOCKQUOTE>
<HR ALIGN=CENTER>
<BR>
<NOTE>It is easy to accidentally remove all print jobs for a printer when you use the lprm command while logged in as root. Take care to use the proper syntax.</NOTE>
<BR>
<HR ALIGN=CENTER>
</BLOCKQUOTE></BLOCKQUOTE>
<P>When lprm removes files from the queue, it echoes back a message to the display. If there are no files to remove, nothing is echoed back (and you will be left wondering what, if anything, happened).
<BR>
<BLOCKQUOTE>
<BLOCKQUOTE>
<HR ALIGN=CENTER>
<BR>
<NOTE>Because users cannot access the Linux printer spooling directories, they can only remove queued print jobs with the lprm command. If you are a system administrator, you may want to let all system users know how to use this command to save unwanted print jobs from printing.</NOTE>
<BR>
<HR ALIGN=CENTER>
</BLOCKQUOTE></BLOCKQUOTE>
<P>If you try to use lprm on a job that is currently being printed, it may not be terminated properly as the file may already reside in the printer's buffer. In some cases, terminating a job that is currently printing can cause the printer to lock because some output format files cannot handle the termination instructions and freeze when the lock file in the spool directory changes. In cases like this, you must use the ps command to find the output filter process ID and then kill that filter.
<BR>
<BLOCKQUOTE>
<BLOCKQUOTE>
<HR ALIGN=CENTER>
<BR>
<NOTE>When you have a printer lockup problem that doesn't solve itself when you use the lpc utility, try killing the lpd daemon and restarting it. If that doesn't work, you probably have to reboot the entire system.</NOTE>
<BR>
<HR ALIGN=CENTER>
</BLOCKQUOTE></BLOCKQUOTE>
<BR>
<A NAME="E68E107"></A>
<H3 ALIGN=CENTER>
<CENTER>
<FONT SIZE=5 COLOR="#FF0000"><B>Summary</B></FONT></CENTER></H3>
<BR>
<P>Handling printers on a Linux system is not onerous, as long as you know the commands and processes that perform the daily tasks you need. Installing the printer is quite easy, although you have to be careful to set the permissions and ownerships properly. Once installed, printers tend to be either trouble-<A NAME="I2"></A>free or troublesome. All you can do is hope for the former!
<P ALIGN=LEFT>
</td>
</tr>
</table>
<!-- begin footer information -->
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -