-->
Previous Table of Contents Next


Chapter 20
Printing

by Jack Tackett

In this chapter
Selecting a Printer to Work with Linux
Knowing What You Need to Configure Printers
Knowing How Printing Works Under Linux
Understanding the Important Programs for Printing
Understanding the Important Directories
Understanding the Important Files
Understanding the /etc/printcap File
Creating a Test printcap Entry
Putting It All Together
Configuring Red Hat Printers

Although everyone thought the computer revolution would bring the paperless office, it hasn’t. More paper is used today than was used 20 years ago. When the UNIX operating system was in its infancy, Bell Labs used it to produce—and print—technical documentation. As a result, UNIX, and thus Linux, has a great many utilities designed around printing (or at least formatting data to be printed). This chapter concentrates on the mechanics of actually printing a file.

The printing systems common to BSD UNIX/Linux are called the lpr systems (Line PrinteR).

Selecting a Printer to Work with Linux

If you can access the printer from MS-DOS, you should be able to print ASCII characters to the printer from Linux. The only downside is that you may not be able to access certain features of your printer from Linux. One of the main reasons is that under Linux, the system first sends the file to be printed to another file. Linux sends the files to a temporary area because printers are relatively slow peripherals, and the system doesn’t want to slow down your session just to print a file. This process is called spooling, and printers are thus called spooled devices. When you print a file in Linux, the file doesn’t go directly to a printer; instead, it goes to a queue to wait its turn to be printed. If your file is the first in the queue, it prints almost immediately.


NOTE:  Spool is an acronym for Simultaneous Peripheral Operation Off Line. The term was coined in the early days of the big IBM mainframes, when smaller computers were used to print reports offline from the mainframe. This technique allowed expensive mainframes to continue their tasks without wasting time on such trivial matters as printing.

Because Linux inherits a great deal of UNIX functionality, Linux supports many types of printers. If you can access your printer from DOS (as mentioned earlier), you should be able to access the printer from Linux.

Knowing What You Need to Configure Printers

This chapter assumes that you know how to edit a text file under Linux and that you have a basic understanding of file ownership and permissions. It also assumes that you have your Linux system set up and running correctly. In particular, if you’re going to use remote printing, your networking subsystems must be installed and operating correctly. Check out the man pages on the commands chmod and chown for more information. Also review Chapter 8, “Using the vi Editor,” for information on using the vi editor because you need to edit several files when configuring your printers.

Knowing How Printing Works Under Linux

The simplest way to print under Linux is to send the print data directly to the printer device. The following command sends a directory listing to the first parallel printer (LPT1 in DOS terms):


ls > /dev/lp0

This method doesn’t take advantage of Linux’s multitasking capabilities because the time taken for this command to finish is however long it takes the printer to actually physically print the data. On a slow printer or a printer that’s deselected or disconnected, this could be a long time. A better method is to spool the data—that is, to collect the print data into a file and then start a background process to send the data to the printer.

Spooling files to be printed later is essentially how Linux works. For each printer, a spool area is defined. Data for the printer is collected in the spool area, one file per print job. A background process (called the printer daemon) constantly scans the spool areas for new files to print. When one appears, the data is sent to the appropriate printer, or despooled. When more than one file is waiting to be printed, the files are printed in the order they’re completed—first in, first out. Thus, the spool area is effectively a queue, and the waiting jobs are often referred to as being in the print queue or queued. In the case of remote printing, the data is first spooled locally as for any other print job, but the background process is told to send the data to a particular printer on a particular remote machine.

The necessary information that the printer daemon needs to do its job—the physical device to use, the spool area to look in, the remote machine and printer for remote printing, and so on—is all stored in a file called /etc/printcap. The details of this file are discussed later in the section “Understanding the /etc/printcap File.”


NOTE:  To Linux, the printer is just another file. But because it is a physical piece of hardware, it will have an entry in the /dev directory. Linux likes to treat physical devices as if they are part of the file system.

The term printer is used to mean a printer as specified in /etc/printcap. The term physical printer is used to mean the thing that actually puts characters on paper. It’s possible to have multiple entries in /etc/printcap that all describe one physical printer but do so in different ways. If this isn’t clear to you, read the section on /etc/printcap.

Understanding the Important Programs for Printing

Five programs comprise the UNIX print system. By default, they are in the locations shown in Table 20.1, are owned by root, belong to the group daemon, and have the permissions listed in the table.

Table 20.1 The Important Printing Programs

File Permissions File Locations

-rwsr-sr-x /usr/bin/lpr
-rwsr-sr-x /usr/bin/lpq
-rwsr-sr-x /usr/bin/lpc
-rwsr-sr-x /usr/bin/lprm
-rwxr-s- - - /usr/sbin/lpd

The first four file permissions in Table 20.1 are used to submit, cancel, and inspect print jobs. /usr/sbin/lpd is the printer daemon.


NOTE:  The locations, ownerships, and permissions in Table 20.1 have been simplified and may be wrong for your system, so note the lpd files and permissions.


Previous Table of Contents Next