📄 ch39.htm
字号:
have an easy-to-use printer installation and configuration utilities like many UNIX
versions. Instead, the printer devices must be created and set up manually.</P>
<P>Parallel printers are referred to as devices <TT>lp0</TT>, <TT>lp1</TT>, or <TT>lp2</TT>,
depending on the address of the parallel port they are used with. (The most common
is the single parallel port on a PC, which is <TT>/dev/lp0</TT>.) Valid parallel
port devices, their addresses, and their usual equivalents under MS-DOS are as shown
here:
<TABLE BORDER="0">
<TR ALIGN="LEFT" rowspan="1">
<TD WIDTH="67" ALIGN="LEFT"><TT>/dev/lp0</TT> </TD>
<TD WIDTH="51" ALIGN="LEFT"><TT>0x03bc</TT> </TD>
<TD ALIGN="LEFT">LPT1 </TD>
</TR>
<TR ALIGN="LEFT" rowspan="1">
<TD WIDTH="67" HEIGHT="28" ALIGN="LEFT"><TT>/dev/lp1</TT> </TD>
<TD WIDTH="51" HEIGHT="28" ALIGN="LEFT"><TT>0x0378</TT> </TD>
<TD HEIGHT="28" ALIGN="LEFT">LPT2 </TD>
</TR>
<TR ALIGN="LEFT" rowspan="1">
<TD WIDTH="67" ALIGN="LEFT"><TT>/dev/lp2<BR>
</TT></TD>
<TD WIDTH="51" ALIGN="LEFT"><TT>0x0278<BR>
</TT></TD>
<TD ALIGN="LEFT">LPT3<BR>
</TD>
</TR>
</TABLE>
<DL>
<DD>
<HR>
<A NAME="Heading14<FONT COLOR="#000077"><B>NOTE:</B> </FONT>To determine the
address of a parallel port, you can use a diagnostic utility (such as DOS's MSD.EXE).
Some BIOS versions display port addresses when the system is booting. If you are
unsure, try the ports starting with <TT>/dev/lp0</TT>, and wait to see whether a
printout is possible. The first parallel port on a PC is typically set to address
<TT>0x03bc</TT>.
<HR>
</DL>
<P>Linux uses the <TT>mknod</TT> (make node) command to create a parallel printer
device file. After the device has been made, the ownership of the device driver file
must be altered to <TT>root</TT> or <TT>daemon</TT>.</P>
<P>The following is a command to make a parallel printer device on the first parallel
port (<TT>/dev/lp0</TT>):<FONT COLOR="#0066FF"></FONT>
<PRE><FONT COLOR="#0066FF">mknod -m 620 /dev/lp0 c 6 0
chown root.daemon /dev/lp0
</FONT></PRE>
<P>In this example, the file permissions are set to mode <TT>620</TT>, the device
<TT>/dev/lp0</TT> is created, and it is set to be a character mode device with a
major device number of <TT>6</TT> and a minor device number of <TT>0</TT>. Usually,
minor device numbers start at <TT>0</TT> and are incremented upward; therefore, because
this is the first printer added, the minor device number is set to <TT>0</TT>.
<DL>
<DT></DT>
</DL>
<DL>
<DD>
<HR>
<A NAME="Heading15<FONT COLOR="#000077"><B>NOTE:</B> </FONT>The ownership <TT>root.daemon</TT>
is a special Linux convention for the daemons run by root. The entry <TT>root.daemon</TT>
does not appear in the <TT>/etc/passwd</TT> file. This uses a convention that lets
the first part of the entry (before the period) indicate the user and the second
part (after the period) represent the group.
<HR>
</DL>
<P>If a different device is configured, the device name itself must be changed to
the device number. For each possible parallel port, the <TT>mknod</TT> commands are
as shown here:<FONT COLOR="#0066FF"></FONT>
<PRE><FONT COLOR="#0066FF">mknod -m 620 /dev/lp0 c 6 0
mknod -m 620 /dev/lp1 c 6 1
mknod -m 620 /dev/lp2 c 6 2
</FONT></PRE>
<P>In these examples, the minor device numbers have been incremented to correspond
to the port number. This is not necessary, but it can help with identification.</P>
<P>After the <TT>mknod</TT> and <TT>chown</TT> commands have been issued, it is advisable
to manually check to ensure that the ownerships are set properly and that a spool
directory has been created. If the spool directory doesn't exist, you have to create
it manually. The permissions and ownership requirements of the spool directory were
given earlier, in the section "The <TT>/etc/printcap</TT> File and Spooling
Directories."
<CENTER>
<H4><A NAME="Heading16<FONT COLOR="#000077">Managing Printers with lpc</FONT></H4>
</CENTER>
<P>Printers are controlled through a utility called <TT>lpc</TT>. The <TT>lpc</TT>
program lets you perform several important functions pertaining to the printers used
on your Linux system:
<UL>
<LI>Display printer status information
<P>
<LI>Enable or disable the printer
<P>
<LI>Enable or disable the printer queue
<P>
<LI>Remove all print requests from a printer's queue
<P>
<LI>Promote a particular print request to the top of the queue
<P>
<LI>Make changes to the <TT>lpd</TT> printer daemon
</UL>
<P>The <TT>lpc</TT> program can't be used for remote printers. It affects only those
directly attached and configured on the local machine.
<DL>
<DT></DT>
</DL>
<DL>
<DD>
<HR>
<A NAME="Heading17<FONT COLOR="#000077"><B>WARNING:</B> </FONT>Be warned that
<TT>lpc</TT> is one of the most unpredictable and unreliable programs included with
the Linux operating system! It can hang up for no obvious reason, and it can also
display erroneous status messages. In some cases, the only way to fix a severely
screwed-up printer system is to reset the machine completely!
<HR>
</DL>
<P>When used without any arguments, <TT>lpc</TT> prompts you for a command. The following
are several valid <TT>lpc</TT> commands and their arguments (a vertical bar indicates
a choice of arguments): <TT>abort </TT>printer_name<TT> | all</TT> Is similar to
the <TT>stop</TT> command, except it doesn't allow any print job that is currently
being printed to finish before stopping the printer. When used with the <TT>all</TT>
argument, all printers are stopped. Any job that is abnormally terminated by the
<TT>abort</TT> command is requeued when the printer is started again. See the <TT>stop</TT>
command for more details about the printer daemon and lock files.</P>
<P><TT>clean </TT>printer_name<TT> | all</TT> Removes all print jobs that are queued,
including any active print jobs. In many cases, the currently printing job proceeds
normally because it has been passed to the printer daemon or the printer's buffer.
All other jobs are removed, though. If the <TT>all</TT> argument is used, all printers
have their print queues cleaned.</P>
<P><TT>disable </TT>printer_name<TT> | all</TT> 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 the 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 <TT>lock</TT> file
in the spool directory.</P>
<P><TT>down </TT>printer_name message Is used to take a printer completely offline,
usually for an extended period. If a message is included, it can be as long as you
want. It is placed in the <TT>status</TT> file in the spool directory and displayed
to users trying to queue to the printer. The <TT>down</TT> command is usually used
when a printer has serious problems and must be removed from the system for more
than a day.</P>
<P><TT>enable </TT>printer_name<TT> | all</TT> Enables the spooling of print requests
to the printer or all printers.</P>
<P><TT>exit</TT> Exits from <TT>lpc</TT> (the same as <TT>quit</TT>).</P>
<P><TT>help </TT>or<TT> ?</TT> Shows a short list of all <TT>lpc</TT> commands. If
an argument is supplied, it displays a one-line description of that command (such
as <TT>help</TT> <TT>abort</TT>).</P>
<P><TT>quit</TT> Exits from <TT>lpc</TT> (the same as <TT>exit</TT>).</P>
<P><TT>restart </TT>printer_name<TT> | all</TT> Restarts the printer daemon, and
is usually used after it has died for an inexplicable reason (which the BSD printer
daemons tend to do). If the argument <TT>all</TT> is supplied, all printer daemons
are restarted.</P>
<P><TT>start </TT>printer_name Starts the printer, allowing it to print requests.
This command starts the printer queue daemon for that printer.</P>
<P><TT>status </TT>printer_name 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 there are no entries in the queue,
no printer daemon will be active. However, if there are entries in the queue and
the printer daemon shows as <TT>no daemon present</TT>, the daemon has died and must
be started again with the <TT>restart</TT> command.</P>
<P><TT>stop </TT>printer_name 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 the <TT>stop</TT> command is issued, the job completes the print process and
then stops printing. The <TT>start</TT> and <TT>stop</TT> commands alter the contents
of the lock file in the print spool directories. The <TT>stop</TT> command also kills
the daemon for spooling to that printer.</P>
<P><TT>topq </TT>printer_name print_ID Moves the print request with print_ID to the
top of the print queue.</P>
<P><TT>topq </TT>printer_name username Moves all print requests owned by username
to the top of the queue. (This is very handy for system administrators who don't
want to wait!)<BR>
<BR>
<TT>up </TT>printer_name Is used to reactivate a printer that was taken down. See
the <TT>down</TT> command for more information.<BR>
<BR>
The <TT>lpc</TT> utility isn't very user-friendly, but it's the only way to handle
printers and their queues in Linux. Several front-end menu-driven utilities are beginning
to appear that simplify this task.
<CENTER>
<H4><A NAME="Heading18<FONT COLOR="#000077">Managing the Printer Queue with
lpq and lprm</FONT></H4>
</CENTER>
<P>Several commands help you administer the printer queue specifically, instead of
relying on the <TT>lpc</TT> command. Two tasks are commonly required by a system
administrator: displaying the current queue and removing print jobs in a queue.</P>
<P>To display the current print queue for any printer, use the <TT>lpq</TT> command.
It has the following syntax:<FONT COLOR="#0066FF"></FONT>
<PRE><FONT COLOR="#0066FF">lpq [-l] [-Pprinter_name] [job_ID ...] [username ...]
</FONT></PRE>
<P>With no arguments at all, <TT>lpq</TT> displays information about the current
printer queues. The <TT>lpq</TT> 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 <TT>-l</TT> option displays more information about each
entry in the printer queue. Usually, only one line of information is displayed.</P>
<P>A specific printer can be displayed with the <TT>-P</TT> 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 job
or jobs queued by the user is shown.
<DL>
<DT></DT>
</DL>
<DL>
<DD>
<HR>
<A NAME="Heading19<FONT COLOR="#000077"><B>NOTE: </B></FONT>Because users can't
access the Linux printer spooling directories, they can remove queued print jobs
only with the <TT>lprm</TT> command. If you are a system administrator, you might
want to let all system users know how to use this command to keep unwanted print
jobs from printing.
<HR>
</DL>
<P>The <TT>lprm</TT> command is used to remove files from a printer queue. This command
is often mistyped as <TT>lpr</TT>, which doesn't remove the file from the queue.
To use <TT>lprm</TT>, you must know the print job ID; or, if you are logged in as
<TT>root</TT>, you can remove all jobs for a particular printer. The syntax of the
<TT>lprm</TT> command is as follows:<FONT COLOR="#0066FF"></FONT>
<PRE><FONT COLOR="#0066FF">lprm [-Pprinter_name] [-] [job_ID ...] [username ...]
</FONT></PRE>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -