Online Book Reader

Home Category

Classic Shell Scripting - Arnold Robbins [51]

By Root 829 0
followed by a summary report:

$ wc /etc/passwd /etc/group

Count data in two files

26 68 1631 /etc/passwd

10376 10376 160082 /etc/group

10402 10444 161713 total

Modern versions of wc are locale-aware: set the environment variable LC_CTYPE to the desired locale to influence wc's interpretation of byte sequences as characters and word separators.

In Chapter 5, we will develop a related tool, wf, to report the frequency of occurrence of each word.

Printing

Compared to computers, printers are slow devices, and because they are commonly shared, it is generally undesirable for users to send jobs directly to them. Instead, most operating systems provide commands to send requests to a print daemon [2] that queues jobs for printing, and handles printer and queue management. Print commands can be handled quickly because printing is done in the background when the needed resources are available.

Printing support in Unix evolved into two camps with differing commands but equivalent functionality, as summarized in Table 4-2. Commercial Unix systems and GNU/Linux usually support both camps, whereas BSD systems offer only the Berkeley style. POSIX specifies only the lp command.

Table 4-2. Printing commands

Berkeley

System V

Purpose

lpr

lp

Send files to print queue

lprm

cancel

Remove files from print queue

lpq

lpstat

Report queue status

Here is an example of their use, first with the Berkeley style:

$ lpr -Plcb102 sample.ps

Send PostScript file to print queue lcb102

$ lpq -Plcb102

Ask for print queue status

lcb102 is ready and printing

Rank Owner Job File(s) Total Size

active jones 81352 sample.ps 122888346 bytes

$ lprm -Plcb102 81352

Stop the presses! Kill that huge job

and then with the System V style:

$ lp -d lcb102 sample.ps

Send PostScript file to print queue lcb102

request id is lcb102-81355 (1 file(s))

$ lpstat -t lcb102

Ask for print queue status

printer lcb102 now printing lcb102-81355

$ cancel lcb102-81355

Whoops! Don't print that job!

lp and lpr can, of course, read input from standard input instead of from command-line files, so they are commonly used at the end of a pipeline.

System management can make a particular single queue the system default so that queue names need not be supplied when the default is acceptable. Individual users can set an environment variable, PRINTER (Berkeley) or LPDEST (System V), to select a personal default printer.

Print queue names are site-specific: a small site might just name the queue printer, and make it the default. Larger sites might pick names that reflect location, such as a building abbreviation and room number, or that identify particular printer models or capabilities, such as bw for a black-and-white printer and color for the expensive one.

Unfortunately, with modern networked intelligent printers, the lprm, cancel, lpq, and lpstat commands are much less useful than they once were: print jobs arrive quickly at the printer and appear to the printer daemon to have been printed already and are thus deleted from the print queue, even though the printer may still be holding them in memory or in a filesystem while other print jobs are still being processed. At that point, the only recourse is to use the printer's control panel to cancel an unwanted job.

Evolution of Printing Technology

Printer technology has changed a lot since Unix was first developed. The industry has moved from large impact printers and electric typewriters that formed characters by hammering a ribbon and paper against a metal character shape, to electrostatic, dot-matrix, inkjet, and laser printers that make characters from tiny dots.

Advances in microprocessors allowed the implementation inside the printer of simple command languages like Hewlett-Packard Printer Command Language (PCL) and HP Graphics Language(HPGL), and complete programming languages—notably, Adobe PostScript. Adobe Portable Document Format (PDF) is a descendant of PostScript that is more compact, but not programmable. PDF offers additional

Return Main Page Previous Page Next Page

®Online Book Reader