This section tells you how to use printers you have set up with FreeBSD. Here is an overview of the user-level commands:
There is also an administrative command, lpc(8), described in the section Administering Printers, used to control printers and their queues.
All three of the commands lpr(1), lprm(1), and lpq(1) accept an
option -P printer-name
to specify on which printer/queue to
operate, as listed in the /etc/printcap file. This enables you
to submit, remove, and check on jobs for various printers. If you do not use the -P
option, then these commands use the printer specified in the PRINTER environment variable. Finally, if you do not have a PRINTER environment variable, these commands default to the printer
named lp.
Hereafter, the terminology default printer means the printer named in the PRINTER environment variable, or the printer named lp when there is no PRINTER environment variable.
To print files, type:
% lpr filename ...
This prints each of the listed files to the default printer. If you list no files, lpr(1) reads data to print from standard input. For example, this command prints some important system files:
% lpr /etc/host.conf /etc/hosts.equiv
To select a specific printer, type:
% lpr -P
printer-name filename ...
This example prints a long listing of the current directory to the printer named rattan:
% ls-l
| lpr-P
rattan
Because no files were listed for the lpr(1) command,
lpr read the data to print from standard input, which
was the output of the ls -l
command.
The lpr(1) command can also accept a wide variety of options to control formatting, apply file conversions, generate multiple copies, and so forth. For more information, see the section Printing Options.
When you print with lpr(1), the data you wish to print is put together in a package called a “print job”, which is sent to the LPD spooling system. Each printer has a queue of jobs, and your job waits in that queue along with other jobs from yourself and from other users. The printer prints those jobs in a first-come, first-served order.
To display the queue for the default printer, type lpq(1). For a specific
printer, use the -P
option. For example, the command
% lpq -P
bamboo
shows the queue for the printer named bamboo. Here is
an example of the output of the lpq command:bamboo is ready and printing Rank Owner Job Files Total Size active kelly 9 /etc/host.conf, /etc/hosts.equiv 88 bytes 2nd kelly 10 (standard input) 1635 bytes 3rd mary 11 ... 78519 bytes
This shows three jobs in the queue for bamboo. The first job, submitted by user kelly, got assigned “job number” 9. Every job for a printer gets a unique job number. Most of the time you can ignore the job number, but you will need it if you want to cancel the job; see section Removing Jobs for details.
Job number nine consists of two files; multiple files given on the lpr(1) command line are treated as part of a single job. It is the currently active job (note the word active under the “Rank” column), which means the printer should be currently printing that job. The second job consists of data passed as the standard input to the lpr(1) command. The third job came from user mary; it is a much larger job. The pathname of the file she is trying to print is too long to fit, so the lpq(1) command just shows three dots.
The very first line of the output from lpq(1) is also useful: it tells what the printer is currently doing (or at least what LPD thinks the printer is doing).
The lpq(1) command also
support a -l
option to generate a detailed long listing.
Here is an example of lpq -l
:
waiting for bamboo to become ready (offline ?) kelly: 1st [job 009rose] /etc/host.conf 73 bytes /etc/hosts.equiv 15 bytes kelly: 2nd [job 010rose] (standard input) 1635 bytes mary: 3rd [job 011rose] /home/orchid/mary/research/venus/alpha-regio/mapping 78519 bytes
If you change your mind about printing a job, you can remove the job from the queue with the lprm(1) command. Often, you can even use lprm(1) to remove an active job, but some or all of the job might still get printed.
To remove a job from the default printer, first use lpq(1) to find the job number. Then type:
% lprm job-number
To remove the job from a specific printer, add the -P
option. The following command removes job number 10 from the queue for the printer
bamboo:
% lprm -P
bamboo 10
The lprm(1) command has a few shortcuts:
Removes all jobs (for the default printer) belonging to you.
Removes all jobs (for the default printer) belonging to user. The superuser can remove other users' jobs; you can remove only your own jobs.
With no job number, user name, or -
appearing on the
command line, lprm(1) removes the
currently active job on the default printer, if it belongs to you. The
superuser can remove any active job.
Just use the -P
option with the above shortcuts to
operate on a specific printer instead of the default. For example, the following
command removes all jobs for the current user in the queue for the printer named
rattan:
% lprm -P
rattan -
Note: If you are working in a networked environment, lprm(1) will let you remove jobs only from the host from which the jobs were submitted, even if the same printer is available from other hosts. The following command sequence demonstrates this:
% lpr-P
rattan myfile % rlogin orchid % lpq-P
rattan Rank Owner Job Files Total Size active seeyan 12 ... 49123 bytes 2nd kelly 13 myfile 12 bytes % lprm-P
rattan 13 rose: Permission denied % logout % lprm-P
rattan 13 dfA013rose dequeued cfA013rose dequeued
The lpr(1) command supports a number of options that control formatting text, converting graphic and other file formats, producing multiple copies, handling of the job, and more. This section describes the options.
The following lpr(1) options control formatting of the files in the job. Use these options if the job does not contain plain text or if you want plain text formatted through the pr(1) utility.
For example, the following command prints a DVI file (from the TeX typesetting system) named fish-report.dvi to the printer named bamboo:
% lpr -P
bamboo -d fish-report.dvi
These options apply to every file in the job, so you cannot mix (say) DVI and ditroff files together in a job. Instead, submit the files as separate jobs, using a different conversion option for each job.
Note: All of these options except
-p
and-T
require conversion filters installed for the destination printer. For example, the-d
option requires the DVI conversion filter. Section Conversion Filters gives details.
-c
Print cifplot files.
-d
Print DVI files.
-f
Print FORTRAN text files.
-g
Print plot data.
-i number
Indent the output by number columns; if you omit number, indent by 8 columns. This option works only with certain conversion filters.
Note: Do not put any space between the
-i
and the number.
-l
Print literal text data, including control characters.
-n
Print ditroff (device independent troff) data.
Format plain text with pr(1) before printing. See pr(1) for more information.
-T title
Use title on the pr(1) header instead
of the file name. This option has effect only when used with the
-p
option.
-t
Print troff data.
-v
Print raster data.
Here is an example: this command prints a nicely formatted version of the ls(1) manual page on the default printer:
% zcat /usr/share/man/man1/ls.1.gz | troff-t
-man | lpr-t
The zcat(1) command
uncompresses the source of the ls(1) manual page and
passes it to the troff(1)
command, which formats that source and makes GNU troff output and passes it to lpr(1), which submits
the job to the LPD spooler. Because we used the
-t
option to lpr(1), the
spooler will convert the GNU troff output into a format the default printer can
understand when it prints the job.
The following options to lpr(1) tell LPD to handle the job specially:
Produce a number of copies of each file in the job instead of just one copy. An administrator may disable this option to reduce printer wear-and-tear and encourage photocopier usage. See section Restricting Multiple Copies.
This example prints three copies of parser.c followed by three copies of parser.h to the default printer:
% lpr -#3
parser.c parser.h
Send mail after completing the print job. With this option, the LPD system will send mail to your account when it finishes handling your job. In its message, it will tell you if the job completed successfully or if there was an error, and (often) what the error was.
Do not copy the files to the spooling directory, but make symbolic links to them instead.
If you are printing a large job, you probably want to use this option. It saves space in the spooling directory (your job might overflow the free space on the filesystem where the spooling directory resides). It saves time as well since LPD will not have to copy each and every byte of your job to the spooling directory.
There is a drawback, though: since LPD will refer to the original files directly, you cannot modify or remove them until they have been printed.
Note: If you are printing to a remote printer, LPD will eventually have to copy files from the local host to the remote host, so the
-s
option will save space only on the local spooling directory, not the remote. It is still useful, though.
Remove the files in the job after copying them to the spooling directory, or
after printing them with the -s
option. Be careful
with this option!
These options to lpr(1) adjust the text that normally appears on a job's header page. If header pages are suppressed for the destination printer, these options have no effect. See section Header Pages for information about setting up header pages.
Replace the hostname on the header page with text. The hostname is normally the name of the host from which the job was submitted.
Replace the job name on the header page with text. The job name is normally the name of the first file of the job, or stdin if you are printing standard input.
Do not print any header page.
Note: At some sites, this option may have no effect due to the way header pages are generated. See Header Pages for details.
As an administrator for your printers, you have had to install, set up, and test them. Using the lpc(8) command, you can interact with your printers in yet more ways. With lpc(8), you can
Start and stop the printers
Enable and disable their queues
Rearrange the order of the jobs in each queue.
First, a note about terminology: if a printer is stopped, it will not print anything in its queue. Users can still submit jobs, which will wait in the queue until the printer is started or the queue is cleared.
If a queue is disabled, no user (except root) can submit jobs for the printer. An enabled queue allows jobs to be submitted. A printer can be started for a disabled queue, in which case it will continue to print jobs in the queue until the queue is empty.
In general, you have to have root privileges to use the lpc(8) command. Ordinary users can use the lpc(8) command to get printer status and to restart a hung printer only.
Here is a summary of the lpc(8) commands. Most of the commands take a printer-name argument to tell on which printer to operate. You can use all for the printer-name to mean all printers listed in /etc/printcap.
Cancel the current job and stop the printer. Users can still submit jobs if the queue is enabled.
Remove old files from the printer's spooling directory. Occasionally, the files that make up a job are not properly removed by LPD, particularly if there have been errors during printing or a lot of administrative activity. This command finds files that do not belong in the spooling directory and removes them.
Disable queuing of new jobs. If the printer is running, it will continue to print any jobs remaining in the queue. The superuser (root) can always submit jobs, even to a disabled queue.
This command is useful while you are testing a new printer or filter installation: disable the queue and submit jobs as root. Other users will not be able to submit jobs until you complete your testing and re-enable the queue with the enable command.
Take a printer down. Equivalent to disable followed by stop. The message appears as the printer's status whenever a user checks the printer's queue with lpq(1) or status with lpc status.
Enable the queue for a printer. Users can submit jobs but the printer will not print anything until it is started.
Print help on the command command-name. With no command-name, print a summary of the commands available.
Start the printer. Ordinary users can use this command if some extraordinary circumstance hangs LPD, but they cannot start a printer stopped with either the stop or down commands. The restart command is equivalent to abort followed by start.
Start the printer. The printer will print jobs in its queue.
Stop the printer. The printer will finish the current job and will not print anything else in its queue. Even though the printer is stopped, users can still submit jobs to an enabled queue.
Rearrange the queue for printer-name by placing the jobs with the listed job numbers or the jobs belonging to username at the top of the queue. For this command, you cannot use all as the printer-name.
Bring a printer up; the opposite of the down command. Equivalent to start followed by enable.
lpc(8) accepts the above commands on the command line. If you do not enter any commands, lpc(8) enters an interactive mode, where you can enter commands until you type exit, quit, or end-of-file.