263 lines
8.3 KiB
HTML
263 lines
8.3 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
|
|
<HTML>
|
|
<HEAD>
|
|
<META NAME="GENERATOR" CONTENT="SGML-Tools 1.0.9">
|
|
<TITLE>The Linux Printing Usage HOWTO: Printing Under Linux</TITLE>
|
|
<LINK HREF="Printing-Usage-HOWTO-3.html" REL=next>
|
|
<LINK HREF="Printing-Usage-HOWTO-1.html" REL=previous>
|
|
<LINK HREF="Printing-Usage-HOWTO.html#toc2" REL=contents>
|
|
</HEAD>
|
|
<BODY>
|
|
<A HREF="Printing-Usage-HOWTO-3.html">Next</A>
|
|
<A HREF="Printing-Usage-HOWTO-1.html">Previous</A>
|
|
<A HREF="Printing-Usage-HOWTO.html#toc2">Contents</A>
|
|
<HR>
|
|
<H2><A NAME="s2">2. Printing Under Linux</A></H2>
|
|
|
|
<P>This section discusses how to print files, examine the print queue, remove
|
|
jobs from the print queue, format files before printing them, and configure
|
|
your printing environment.
|
|
<P>
|
|
<H2><A NAME="ss2.1">2.1 History of Linux Printing</A>
|
|
</H2>
|
|
|
|
<P>
|
|
<!--
|
|
printing!history of
|
|
-->
|
|
|
|
The Linux printing system---the <EM>lp</EM> system---is a port of the source
|
|
code written by the Regents of the University of California for the Berkeley
|
|
Software Distribution version of the UNIX operating system.
|
|
<P>
|
|
<H2><A NAME="ss2.2">2.2 Printing a File Using <EM>lpr</EM></A>
|
|
</H2>
|
|
|
|
<P>
|
|
<!--
|
|
printing!using lpr command
|
|
-->
|
|
|
|
<!--
|
|
lpr command!usage example
|
|
-->
|
|
|
|
By far, the most simplistic way to print in the Linux operating system is
|
|
to send the file to be printed directly to the printing device. One way
|
|
to do this is to use the <EM>cat</EM> command. As the <CODE>root</CODE> user,
|
|
one could do something like
|
|
<P>
|
|
<BLOCKQUOTE><CODE>
|
|
<PRE>
|
|
# cat thesis.txt > /dev/lp
|
|
</PRE>
|
|
</CODE></BLOCKQUOTE>
|
|
<P>In this case, <CODE>/dev/lp</CODE> is a symbolic link to the actual printing
|
|
device---be it a dot-matrix, laser printer, typesetter, or plotter. (See
|
|
<EM>ln</EM>(1) for more information on symbolic links.)
|
|
<P>For the purpose of security, only the <CODE>root</CODE> user and users in the
|
|
same group as the print daemon are able to write directly to the printer.
|
|
This is why commands such as <EM>lpr</EM>, <EM>lprm</EM>, and <EM>lpq</EM>
|
|
have to be used to access the printer.
|
|
<P>Because of this, users have to use <EM>lpr</EM> to print a file. The
|
|
<EM>lpr</EM> command takes care of all the initial work needed to print
|
|
the file, and then it hands control over to another program, <EM>lpd</EM>,
|
|
the line printing daemon. The line printing daemon then tells the printer
|
|
how to print the file.
|
|
<P>When <EM>lpr</EM> is executed, it first copies the specified file to a
|
|
certain directory (the spool directory) where the file remains until
|
|
<EM>lpd</EM> prints it. Once <EM>lpd</EM> is told that there is a file to
|
|
print, it will spawn a copy of itself (what we programmers call forking).
|
|
This copy will print our file while the original copy waits for more
|
|
requests. This allows for multiple jobs to be queued at once.
|
|
<P>The syntax of <EM>lpr</EM>(1) is a very familiar one,
|
|
<P>
|
|
<BLOCKQUOTE><CODE>
|
|
<PRE>
|
|
$ lpr [ options ] [ filename ... ]
|
|
</PRE>
|
|
</CODE></BLOCKQUOTE>
|
|
<P>If <CODE>filename</CODE> is not specified, <EM>lpr</EM> expects input to come
|
|
from standard input (usually the keyboard, or another program's output).
|
|
This enables the user to redirect a command's output to the print spooler.
|
|
As such,
|
|
<P>
|
|
<BLOCKQUOTE><CODE>
|
|
<PRE>
|
|
$ cat thesis.txt | lpr
|
|
</PRE>
|
|
</CODE></BLOCKQUOTE>
|
|
<P>or,
|
|
<P>
|
|
<BLOCKQUOTE><CODE>
|
|
<PRE>
|
|
$ pr -l60 thesis.txt | lpr
|
|
</PRE>
|
|
</CODE></BLOCKQUOTE>
|
|
<P>The <EM>lpr</EM> command accepts several command-line arguments that allow a
|
|
user to control how it works. Some of the most widely used arguments are:
|
|
-<B>P</B>printer specifies the printer to use, -<B>h</B> suppresses printing of
|
|
the burst page, -<B>s</B> creates a symbolic link instead of copying the file
|
|
to the spool directory (useful for large files), and -<B>#</B>num
|
|
specifies the number of copies to print. An example interaction with
|
|
<EM>lpr</EM> might be something like
|
|
<P>
|
|
<BLOCKQUOTE><CODE>
|
|
<PRE>
|
|
$ lpr -#2 -sP dj thesis.txt
|
|
</PRE>
|
|
</CODE></BLOCKQUOTE>
|
|
<P>This command will create a symbolic link to the file <CODE>thesis.txt</CODE> in
|
|
the spool directory for the printer named <EM>dj</EM>, where it would be
|
|
processed by <EM>lpd</EM>. It would then print a second copy of
|
|
<CODE>thesis.txt</CODE>.
|
|
<P>For a listing of all the options that <EM>lpr</EM> will recognize, see
|
|
<EM>lpr</EM>(1).
|
|
<P>
|
|
<H2><A NAME="ss2.3">2.3 Viewing the Print Queue with <EM>lpq</EM></A>
|
|
</H2>
|
|
|
|
<P>
|
|
<!--
|
|
printing!using lpq command
|
|
-->
|
|
|
|
<!--
|
|
lpq command!usage example
|
|
-->
|
|
|
|
To view the contents of the print queue, use the <EM>lpq</EM> command.
|
|
Issued without arguments, it returns the contents of the default printer's
|
|
queue.
|
|
<P>The returned output of <EM>lpq</EM> can be useful for many purposes.
|
|
<P>
|
|
<BLOCKQUOTE><CODE>
|
|
<PRE>
|
|
$ lpq
|
|
lp is ready and printing
|
|
Rank Owner Job Files Total Size
|
|
active mwf 31 thesis.txt 682048 bytes
|
|
</PRE>
|
|
</CODE></BLOCKQUOTE>
|
|
<P>
|
|
<H2><A NAME="ss2.4">2.4 Canceling a Print Job Using <EM>lprm</EM></A>
|
|
</H2>
|
|
|
|
<P>
|
|
<!--
|
|
printing!using lprm command
|
|
-->
|
|
|
|
<!--
|
|
lprm command!usage example
|
|
-->
|
|
|
|
Another useful feature of any printing system is the ability to cancel a job
|
|
that has been previously queued. To do this, use <EM>lprm</EM>.
|
|
<P>
|
|
<BLOCKQUOTE><CODE>
|
|
<PRE>
|
|
$ lprm -
|
|
</PRE>
|
|
</CODE></BLOCKQUOTE>
|
|
<P>The above command cancels all of the print jobs that are owned by the user
|
|
who issued the command. A single print job can be canceled by first getting
|
|
the job number as reported by <EM>lpq</EM> and then giving that number to
|
|
<EM>lprm</EM>. For example,
|
|
<P>
|
|
<BLOCKQUOTE><CODE>
|
|
<PRE>
|
|
$ lprm 31
|
|
</PRE>
|
|
</CODE></BLOCKQUOTE>
|
|
<P>would cancel job 31 (<CODE>thesis.txt</CODE>) on the default printer.
|
|
<P>
|
|
<H2><A NAME="ss2.5">2.5 Controlling the lpd program with <EM>lpc</EM></A>
|
|
</H2>
|
|
|
|
<P>
|
|
<!--
|
|
printing!using lpc command
|
|
-->
|
|
|
|
<!--
|
|
lpc command!usage example
|
|
-->
|
|
|
|
The <EM>lpc</EM>(8) program is used to control the printers that lpd serves.
|
|
you can enable or disable a printer or its queues, rearrange entries within
|
|
a queue, and get a status report on the printers and their queues.
|
|
Lpc is mostly used in a setup where there are multiple printers hanging off
|
|
one machine.
|
|
<P>
|
|
<BLOCKQUOTE><CODE>
|
|
<PRE>
|
|
$ lpc
|
|
</PRE>
|
|
</CODE></BLOCKQUOTE>
|
|
<P>The above will start the lpc program. By default, this enters you into
|
|
an interactive mode, and you can begin issuing commands. The other option
|
|
is to issue an lpc command on the command line.
|
|
<P>
|
|
<BLOCKQUOTE><CODE>
|
|
<PRE>
|
|
$ lpc status all
|
|
</PRE>
|
|
</CODE></BLOCKQUOTE>
|
|
<P>A list of the available commands are in the <EM>lpd</EM> man page, but here
|
|
are a few of the major commands you'll want to know about. Any commands
|
|
marked with <EM>option</EM> can either be a printer name (lp, print, etc) or
|
|
the keyword <CODE>all</CODE>, which means all printers.
|
|
<P>
|
|
<UL>
|
|
<LI> disable <EM>option</EM> - prevents any new printer job from being entered</LI>
|
|
<LI> down <EM>option</EM> - disables all printing on the printer</LI>
|
|
<LI> enable <EM>option</EM> - allow new jobs to enter the print queue</LI>
|
|
<LI> quit (or exit) - leave lpc</LI>
|
|
<LI> restart <EM>option</EM> - restarts lpd for that printer</LI>
|
|
<LI> status <EM>option</EM> - print status of printer</LI>
|
|
<LI> up <EM>option</EM> - enable everything and start a new lpd</LI>
|
|
</UL>
|
|
<P>
|
|
<H2><A NAME="ss2.6">2.6 The RedHat printtool</A>
|
|
</H2>
|
|
|
|
<P>
|
|
<!--
|
|
printing!using Red Hat printool
|
|
-->
|
|
|
|
<!--
|
|
Red Hat Linux!printool
|
|
-->
|
|
|
|
<!--
|
|
printool utility
|
|
-->
|
|
|
|
Just a quick note here on RedHat's amazing printtool program. It seems
|
|
to do everything that a magicfilter would do. RedHat already installs many
|
|
of the programs to do the filtering. Here's how I have my printer set up
|
|
under RH 4.0 with an HP LJ 4L connected to my parallel port (should be
|
|
the same for other versions of RH as well).
|
|
<UL>
|
|
<LI>Become root and fire up printtool (if you su'ed, you remembered to
|
|
SETENV DISPLAY :0.0 and xhost +, right?)</LI>
|
|
<LI>Click "Add", and hit "OK" for a local printer.</LI>
|
|
<LI>Fill in the printer device (/dev/lp1 for me)</LI>
|
|
<LI>Fill in the input filter - Select a printer type, resolution, and paper
|
|
size (ljet4, 300x300, and letter)</LI>
|
|
<LI>Hit "OK" all the way back, and restart the lpd.</LI>
|
|
</UL>
|
|
|
|
Just like rolling an /etc/printcap file by hand, you can have multiple
|
|
printer definitions for each physical printer. One for different paper
|
|
sizes, resolutions, etc.
|
|
<P>
|
|
<HR>
|
|
<A HREF="Printing-Usage-HOWTO-3.html">Next</A>
|
|
<A HREF="Printing-Usage-HOWTO-1.html">Previous</A>
|
|
<A HREF="Printing-Usage-HOWTO.html#toc2">Contents</A>
|
|
</BODY>
|
|
</HTML>
|