Linux Cookbook PDF
Linux Cookbook PDF
Michael Stutz
PRESS
An imprint of No Starch Press, Inc.
San Francisco
The Linux Cookbook. Copyright c 2001 by Michael Stutz.
All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechan-
ical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission
of the copyright owner and the publisher.
Printed in the United States of America
1 2 3 4 5 6 7 8 9 10–04 03 02 01
Trademarked names are used throughout this book. Rather than use a trademark symbol with every occurrence of a trademarked
name, we are using the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of
infringement of the trademark.
Co-publishers: William Pollock and Phil Hughes
Project Editor: Karol Jurado
Assistant Editor: Nick Hoff
Cover Design: Octopod Studios
Typesetting and Design: Michael Stutz
Technical Editor: Scott Schwartz
Copyeditor: Andy Carroll
Proofreader: Elisabeth Beller
Distributed to the book trade in the United States by Publishers Group West, 1700 Fourth Street, Berkeley, California 94710,
phone: 800-788-3123 or 510-528-1444, fax: 510-528-3444
Distributed to the book trade in Canada by Jacqueline Gross & Associates, Inc., 195 Allstate Parkway, Markham, Ontario L3R
4T8 Canada, phone: 905-477-0722, fax: 905-477-8619
For information on translations or book distributors outside the United States, please contact No Starch Press, Inc. directly:
No Starch Press, Inc.
555 De Haro Street, Suite 250, San Francisco, CA 94107
phone: 415-863-9900; fax: 415-863-9950; info@nostarch.com; www.nostarch.com
The information in this book is distributed on an “As Is” basis, without warranty. While every precaution has been taken in the
preparation of this work, neither the author nor No Starch Press, Inc. shall have any liability to any person or entity with respect
to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in it.
This official author’s edition is published by exclusive arrangement with No Starch Press, Inc.
Library of Congress Cataloging-in-Publication Data
Stutz, Michael.
The Linux cookbook / Michael Stutz.
p. cm.
ISBN 1-886411-48-4 (pbk.)
1. Linux. 2. Operating systems (Computers) I. Title.
Format of Recipes
Each recipe is numbered with at least two figures. These figures are constructed as follows: the first
number always corresponds to the chapter number, and the second to the section of the recipe. For
example, Chapter 3 is The Shell, and Recipe No. 3.5 is the fifth recipe on shells, Section 3.5 [Recording
a Shell Session], page 41.
Sometimes recipes are divided into subsections, with a third number specifying the specific recipe—
for example, Recipe No. 3.4 is on the subject of command history in the shell, and is divided further
into subsections; Recipe No. 3.4.2 is the second recipe on command history, Section 3.4.2 [Specifying a
Command from Your History], page 41.
Each recipe describes a method for completing a specific task on the system; these tasks require at
least one software program. The software programs or files a recipe calls for are its ingredients.
The recipes are structured as follows:
1. Recipe number and title of the recipe.
2. Special ingredients, if any. The Debian package(s) and/or or URLs where the program(s) can be
obtained are listed, if they are available.
The Linux Cookbook: Tips and Techniques for Everyday Use
Debian classifies packages in varying level of importance, from ‘required’ packages that all
systems must have in order to run, to ‘optional’ and ‘extra’ packages that you only install if
you want them. If a described software package is in the first two given categories—‘required’
and ‘important’—then I assume you have it installed, and the package name isn’t listed here.
In the rare case that a software package I describe is not yet available as a Debian package, I just
give the URL where to obtain the source packages for that software; have your system administrator
install it.
3. Special preparation methods or description, if any. When a configurable program is described, the
standard setup as provided by the Debian distribution is assumed, unless otherwise specified here.
4. Description of the recipe and “cooking” method proper.
5. Remarks concerning the results and use.
6. Bulleted example of the method in a specific context.
7. Extra commands or actions you might want to do next.
8. Variations on the recipe, with additional examples.
9. Special notes or references to further information.
Not all of these items may be present in a given recipe.
Typographical Conventions
All recipes have at least one example that demonstrates it.
¯ The text that describes what the example does appears just before the example itself, and is offset
from the text with a bullet, like this.
¯ A given recipe may have several variations; each is offset with its own bullet.
¯ The names of documents or users that are used in some recipes may not always reference actual
documents or users on your system, but demonstrate the general principles involved. So when I
show how to print a file called ‘resume’, you might not necessarily have a file with that name on
your system, but you should understand the idea which the recipe demonstrates.
« ¨
Sometimes, a terminal screen is shown to illustrate an interactive session:
ª$ ©
In examples where a shell prompt is displayed, the default current working directory is omitted in the
prompt and just a ‘$’ is used; when a command outputs text and then exits, the last line of an example
contains a ‘$’ character to denote the return to a shell prompt. Don’t worry if this sounds strange to you
now; all of this “shell” business is explained in Chapter 3 [The Shell], page 33.
When a command exits and returns to the shell prompt without outputting text, the final shell prompt
character is omitted, and a cartouche border is not drawn around the example; this was purely an aesthetic
decision.
The names of files or directories appear in the text as ‘file’; commands appear as command, and
strings of text are typeset like ‘some text’.
Text you type is written like this, just as in the examples, and when a specific key on the keyboard
is mentioned, its conventional name is displayed in a box. For example, RET denotes the ‘Return’ key
on the keyboard.
In examples where keys are meant to be pressed and held down together, the keys are separated by
hyphens; the hyphens are not meant to be literally pressed. For example, pressing the CTRL, ALT, and
DEL keys and holding them down at the same time is a combination that has meaning in some operating
systems (including Linux, where this keystroke means to shut down the system and reboot the computer);
it is represented like this:
CTRL-ALT-DEL
The CTRL (‘Control’) key is always used in combination with another key; these combinations are
denoted by C-x , where x is the second key. These combinations are read as ‘control-x ’, where x is
the name of the second key. To type one of these combinations, press and hold CTRL, press the second
key, and then release both keys.
This key is labelled ‘Enter’ on some keyboards.
The Linux Cookbook: Tips and Techniques for Everyday Use
¯ For example, to type C-d (pronounced ‘control d’), press and hold CTRL, type the D key, and
then release both keys.
In some applications (notably, the Emacs editor; see Section 10.2 [Emacs], page 108), the META key
is used with another key, in the same way as SHIFT; these combinations are denoted by M-x , where x
is the second key. Most keyboards today don’t have a META key, even though the term is still in use;
instead, press and release ESC, and then type the second key.
¯ To type M-c, press and release ESC, and then press and release the C key.
You can sometimes also use the ALT key for the META key. This often does not work in the X
Window System, but in the console you can press and hold ALT and then type the second key just as you
would with a CTRL key sequence.
¯ So to type M-c with the ALT key, press and hold ALT, press the C key, and then release both keys.
Both CTRL and META sequences are not case-sensitive; that is, pressing X in the last example is the
same as pressing x (although x is certainly easier to type). By convention, the C- or M- prefix is always
given as an uppercase letter, and the key which follows is always given as a lowercase letter.
Menu items in an application are written like Menu Item; the names of command functions are
written as Function.
For aesthetic purposes, a physical space appears in the text between commands and the finalRET that
ends a command line, and should not be literally typed (although nothing bad will happen should you
actually type this space). Where explicitly pressing the space bar is called for, that key is represented in
examples by SPC.
The Linux Cookbook is available in both hardcopy and as a machine-readable file. The latest
edition of this book in etext (“electronic text”) form is always available from its distribution site
(http://dsl.org/cookbook/) on the World Wide Web. This site includes the most up-to-date
complete text (in both HTML and GNU Info formats), and provides a method for purchasing the latest
edition of the hardcopy book at a discount.
Every effort has been made to include only the best free software recipes for accomplishing tasks in
the easiest and most efficient manner, and they are believed to be correct. Suggestions, comments, and
bug reports are always welcome; you can contact the author via email at stutz@dsl.org.
Acknowledgments
This is not a book that was borne easily. Conception, took but an idle moment—but once the idea
had been implanted, I found resistance and setbacks at every turn. It was only through the help of the
following individuals that this book with my name on its cover was finally brought forth, and has now
found its way to you.
Everyone involved with this book at No Starch Press (http://www.nostarch.com/) deserves
a hearty round of thanks. Bill Pollock has published this book precisely according to its author’s vision,
and had the discernment and foresight to allow that a copylefted edition (with corresponding source
data) be made available in conjunction with the hardcopy book. Project manager Karol Jurado worked
ceaselessly to keep the production flowing, while dealing with my input files, and giving opinion and
advice on all manners of obtuse esoterica whenever the sudden need to know came over me. Both
Elisabeth Beller and Andy Carroll contributed improvements to the text.
Steve Turner and the National Writers Union (http://www.nwu.org/) played a major role in
helping to ensure that this book could be completed, copylefted, and in the hands of Linux users like
yourself. Carol Criccow gave invaluable legal assistance, and various advice and assistance came from
the NWU’s JoAnn Kawell, Philip Mattera, Judy Helm, and Bonnie Britt.
Wendy Seltzer, Fellow, The Berkman Center for Internet & Society at Harvard Law School
(http://cyber.law.harvard.edu/) assisted with the conception of the Design Science License
(DSL), which is used in this book. She gave an initial review of the license draft and provided her exper-
tise and advice throughout the entire process.
Thanks to David Sims, Chris Coleman, and Terrie Schweitzer, who’ve all been great folks to work
with at the O’Reilly Network (http://oreillynet.com/), where my “Living Linux” column runs.
I am indebted to Buwei Yang Chao, whose How To Cook and Eat In Chinese (John Day Company,
1945) served as much of the inspiration behind the tone and structure of this book. I feel the same
regard for two other authors who have come before me, and whose work has had a direct influence in the
writing of this book—Dr. Lee Su Jan (The Fine Art of Chinese Cooking, Gramercy Publishing 1962)
and Andrew Walker (The UNIX Environment, Wiley 1984).
Thanks also go out to Kenneth W. Melvin, and to the members of the “Byline” forum on the WELL;
both were sources of advice and feedback early in the project. The art-hackers of the linart mailing
list (http://linart.net/) entertained initial discussion of the idea of this book as it first occurred,
and the “elders” Ann and Walt gave various support for which I am grateful.
Finally, I must thank Jack Angelotta, Jon Konrath, Steven Snedker, and mrs (Marie Stutz), who all
listened to the unbelievable as it happened, and stood by—even in moments of terror.
The Linux Cookbook: Tips and Techniques for Everyday Use
PART ONE: Working with Linux
The Linux Cookbook: Tips and Techniques for Everyday Use
1 Introduction
Before we get into “cooking” and the recipes proper, this first part of the book deals with preliminaries,
explaining the general techniques and methods for working with Linux—including how to get the system
ready for use, and how to run commands on the system.
The rest of the book is all recipes, which are sorted in sections by the tasks they perform or the objects
they work on—such as text, files, images, and so forth.
Unix, the original ancestor of Linux, is an operating system. Or at least it was an operating system; the
original system known as Unix proper is not the “Unix” we know and use today; there are now many
“flavors” of Unix, of which Linux has become the most popular.
A product of the 1960s, Unix and its related software was invented by Dennis Ritchie, Ken Thompson,
Brian Kernighan, and other hackers at Bell Labs in 1969; its name was a play on “Multics,” another
operating system of the time.
In the early days of Unix, any interested party who had the hardware to run it on could get a tape
of the software from Bell Labs, with printed manuals, for a very nominal charge. (This was before the
era of personal computing, and in practice, mostly only universities and research laboratories did this).
Local sites played with the software’s source code, extending and customizing the system to their needs
and liking.
Beginning in the late 1970s, computer scientists at the University of California, Berkeley, a licensee
of the Unix source code, had been making their own improvements and enhancements to the Unix source
during the course of their research, which included the development of TCP/IP networking. Their work
became known as the BSD (“Berkeley Systems Distribution”) flavor of Unix.
The source code of their work was made publicly available under licensing that permitted redistribu-
tion, with source or without, provided that Berkeley was credited for their portions of the code. There
are many modern variants of the original BSD still actively developed today, and some of them—such as
NetBSD and OpenBSD—can run on personal computers.
NOTE: The uppercase word ‘UNIX’ became a trademark of AT&T (since transferred to other organiza-
tions), to mean their particular operating system. But today, when people say “Unix,” they usually mean
“a Unix-like operating system,” a generalization that includes Linux.
If you’d like further information on this topic, you might be interested in consulting A Quarter Cen-
tury of UNIX by Peter H. Salus (Addison-Wesley 1994), which has become the standard text on the
subject.
The name “Unix” was first written as “Unics,” which stood for “Uniplex Information and Computing System.”
The Linux Cookbook: Tips and Techniques for Everyday Use
Over the years, Unix’s popularity grew. After the divestiture of AT&T, the tapes of the source code that
Bell Labs provided became a proprietary, commercial product: AT&T UNIX. But it was expensive, and
didn’t come with the source code that made it tick. Even if you paid extra for a copy of the sources, you
couldn’t share with your programmer colleagues any improvements or discoveries you made.
By the early 1980s, proprietary software development, by only-for-profit corporations, was quickly
becoming the norm—even at universities. More software was being distributed without source code than
ever before.
In 1984, while at the Massachusetts Institute of Technology in Cambridge, Massachusetts, hacker
Richard Stallman saw his colleagues gradually accept and move to this proprietary development model.
He did not accept the kind of world such proprietism would offer: no sharing your findings with your
fellow man, no freedom for anyone to improve a published work.
So instead of giving in to the world of non-free computing, Stallman decided to start a project to build
and assemble a new Unix-like operating system from scratch, and make its source code free for anyone
to copy and modify. This was the GNU Project (“GNU’s Not Unix”).
The GNU Project’s software would be licensed in such a way so that everyone was given the freedom
to copy, distribute, and modify their copy of the software; as a result, this kind of software became known
as free software.
Individuals and businesses may charge for free software, but anyone is free to share copies with their
neighbors, change it, or look at its source code to see how it works. There are no secrets in free software;
it’s software that gives all of its users the freedom they deserve.
Proprietary software strictly limits these freedoms—in accordance with copyright law, which was
formulated in an age when works were normally set and manipulated in physical form, and not as non-
physical data, which is what computers copy and modify.
Free software licensing was developed as a way to work around the failings of copyright law, by
permitting anyone to copy and modify a work, though under certain strict terms and conditions. The GNU
Project’s GNU General Public License (http://www.gnu.org/copyleft/gpl.txt), or GNU
GPL, is the most widely used of all free software licenses. Popularly called a “copyleft,” it permits anyone
to copy or modify any software released under its terms—provided all derivatives or modifications are
released under the same terms, and all changes are documented.
The term open source was first introduced by some free software hackers in 1998 to be a marketing term
for “free software.” They felt that some people unfamiliar with the free software movement—namely,
large corporations, who’d suddenly taken an interest in the more than ten years’ worth of work that had
been put into it—might be scared by the word “free.” They were concerned that decision-makers in these
corporations might confuse free software with things like freeware, which is software provided free of
charge, and in executable form only. (Free software means nothing of the sort, of course; the “free” in
“free software” has always referred to freedom, not price.)
The Open Source Initiative (OSI) was founded to promote software that conforms with their public
“Open Source Definition,” which was derived from the “Debian Free Software Guidelines” (DFSG), orig-
No such “official GNU” operating system has yet been released in its entirety, but most people today consider Linux-based
free software systems to be the effective realization of their goals—hence the “GNU” in “Debian GNU/Linux.”
inally written by Bruce Perens as a set of software inclusion guidelines for Debian. All free software—
including software released under the terms of the GNU General Public License—conforms with this
definition.
But some free software advocates and organizations, including the GNU Project, do not endorse the
term “open source” at all, believing that it obscures the importance of “freedom” in this movement.
Whether you call it free software, open source software, or something else, there is one fundamental
difference between this kind of software and proprietary, non-free software—and that is that free software
always ensures that everyone is granted certain fundamental freedoms with respect to that software.
It takes more than individual software programs to make something that we can use on our computers—
someone has to put it all together. It takes time to assemble the pieces into a cohesive, usable collection,
and test it all, and then keep up to date with the new developments of each piece of software (a small
change in any one of which may introduce a new software dependency problem or conflict with the rest).
A Linux distribution is such an assemblage. You can do it yourself, of course, and “roll your own”
distribution—since it’s all free software, anyone can add to it or remove from it and call the resulting
concoction their own. Most people, however, choose to leave the distribution business to the experts.
For the purposes of this book, I will assume that you are using the Debian GNU/Linux distribution,
which, of all the major distributions, is the only one designed and assembled in the same manner that the
Linux kernel and most other free software is written—by individuals.
And when I say “Linux” anywhere in this book (including in the title), unless noted, I am not referring
to the bare kernel itself, but to the entire working free software system as a whole. This is often called
“GNU/Linux.”
There are many other distributions, and some of them are quite acceptable—many users swear by Red
Hat Linux, for example, which is certainly popular, and reportedly easy to install. The SuSE distribution
You can extend this “free software movement” to be part of a greater “free information” or “free speech” movement, to
include all other kinds of free works—including works of literature and music.
Presumably, many of these courses use Linux now.
This was not the original name, however. Torvalds had originally called it freax, for “‘free’ + ‘freak’ + the obligatory
‘-x’”; while the 1990s were fast becoming the “freaky” alterna decade (at least in fashion), more people seemed to favor
“Linux,” and the name stuck.
The GNU Project’s own kernel is called Hurd, and is still in development; Debian’s experimental distribution of a Hurd-
based free softare system, not yet publicly released, is called Debian GNU/Hurd.
The Linux Cookbook: Tips and Techniques for Everyday Use
is very well-received in Europe. So when people speak of Debian, Red Hat, SuSE, and the like in terms
of Linux, they’re talking about the specific distribution of Linux and related software, as assembled
and repackaged by these companies or organizations (see Appendix B [Linux Resources on the Web],
page 321). The core of the distributions are the same—they’re all the Linux kernel, the GNU Project
software, and various other free software—but each distribution has its own packaging schemes, defaults,
and configuration methods. It is by no means wrong to install and use any of these other distributions,
and every recipe in this book should work with all of them (with the exception of variations that are
specific to Debian systems, and are labelled as such in the text).
In Debian’s early days, it was referred to as the “hacker’s distro,” because it could be very difficult
for a newbie to install and manage. However, that has changed—any Linux newbie can install and use
today’s Debian painlessly.
NOTE: I recommend Debian because it is non-corporate, openly developed, robust (the standard Debian
CD-ROM set comes with more than 2,500 different software packages!), and it is entirely committed to
free software by design (yes, there are distributions which are not).
To understand the way tasks are performed on Linux, some discussion on the philosophy behind the
software that Linux is built upon is in order. A dip in these inviting waters will help clarify the rôle of
this book as “cookbook.”
The fact that the Unix operating system has survived for more than thirty years should tell us some-
thing about the temerity of its design considerations. One of these considerations—perhaps its most
endearing—is the “tools” philosophy.
Most operating systems are designed with a concept of files, come with a set of utility programs
for handling these files, and then leave it to the large applications to do the interesting work: a word
processor, a spreadsheet, a presentation designer, a Web browser. (When a few of these applications
recognize each other’s file formats, or share a common interface, the group of applications is called a
“suite.”)
Each of these monolithic applications presumably has an “open file” command to read a file from
disk and open it in the application; most of them, too, come with commands for searching and replacing
text, checking spelling, printing the current document, and so on. The program source code for handling
all of these tasks must be accounted for separately, inside each application—taking up extra space both
in memory and on disk. This is the anti-Unix approach.
And in the case of proprietary software, all of the actual program source code is kept from the public—
so other programmers can’t use, build on, or learn from any of it. This kind of closed-source software is
presented to the world as a kind of magic trick: if you buy a copy of the program, you may use it, but
you can never learn how the program actually works.
The result of this is that the code to handle essentially the same function inside all of these different
applications must be developed by programmers from scratch, separately and independently of the others
each time—so the progress of society as a whole is set back by the countless man-hours of time and
energy programmers must waste by inefficiently reinventing all the same software functions to perform
the same tasks, over and over again.
Unix-like operating systems don’t put so much weight on application programs. Instead, they come
with many small programs called tools. Each tool is generally capable of performing a very simple,
specific task, and performing it well—one tool does nothing but output the file(s) or data passed to it, one
tool spools its input to the print queue, one tool sorts the lines of its input, and so on.
An important early development in Unix was the invention of “pipes,” a way to pass the output of one
tool to the input of another. By knowing what the individual tools do and how they are combined, a user
could now build powerful “strings” of commands.
Just as the tensile strength of steel is greater than the added strength of its components—nickel, cad-
mium, and iron—multiple tools could then be combined to perform a task unpredicted by the function of
the individual tools. This is the concept of synergy, and it forms the basis of the Unix tools philosophy.
Here’s an example, using two tools. The first tool, called who, outputs a list of users currently logged
on to the system (see Section 2.6.2 [Listing Who Is on the System], page 23). The second tool is called
wc, which stands for “word count”; it outputs a count of the number of words (or lines or characters) of
the input you give it (see Section 12.1 [Counting Text], page 133).
By combining these two tools, giving the wc command the output of who, you can build a new
« ¨
command to list the number of users currently on the system:
$ who | wc -l RET
4
ª$
©
The output of who is piped—via a “pipeline,” specified by the vertical bar (‘|’) character—to the
input of wc, which through use of the ‘-l’ option outputs the number of lines of its input.
In this example, the number 4 is shown, indicating that four users are currently logged on the system.
(Incidentally, piping the output of who to wc in this fashion is a classic tools example, and was called
“the most quoted pipe in the world” by Andrew Walker in The UNIX Environment, a book that was
published in 1984.)
Another famous pipeline from the days before spell-check tools goes something like this:
$ tr -cs A-Za-z ’\012’ | tr A-Z a-z | sort -u |
comm -23 - /usr/dict/words RET
This command (typed all on one line) uses the tr, sort, and comm tools to make a spelling
checker—after you type this command, the lines of text you type (until you interrupt it) are converted
to a single-column list of lowercase words with two calls of tr, sorted in alphabetical order while fer-
reting out all duplicates, the resultant list which is then compared with ‘/usr/dict/words’, which
is the system “dictionary,” a list of properly-spelled words kept in alphabetical order (see Section 11.1
[Spelling], page 121).
Collective sets of tools designed around a certain kind of field or concept were called “workbenches”
on older Unix systems; for example, the tools for checking the spelling, writing style and grammar of
their text input were part of the “Writer’s Workbench” package (see Section 11.3 [Checking Grammar],
page 127).
Today the GNU Project publishes collections of tools under certain general themes, such as the “GNU
text utilities” and “GNU file utilities,” but the idea of “workbenches” is generally not part of the idiom
of today’s Unix-based systems. Needless to say, we still use all kinds of tools for all kinds of purposes;
the great bulk of this book details various combinations of tools to obtain the desired results for various
common tasks.
You’ll find that there’s usually one tool or command sequence that works perfectly for a given task,
but sometimes a satisfactory or even identical result can be had by different combinations of different
tools—especially at the hands of a Unix expert. (Traditionally, such an expert was called a wizard.)
Some tasks require more than one tool or command sequence. And yes, there are tasks that require
more than what these simple craft or hand tools can provide. Some tasks need more industrial production
techniques, which are currently provided for by the application programs. So we still haven’t avoided
applications entirely; at the turn of the millennium, Linux-based systems still have them, from editors to
browsers. But our applications use open file formats, and we can use all of our tools on these data files.
Because of this approach, and because of its free and open nature, I have come to call Linux a “synergetic” operating system,
in honor of the late R. Buckminster Fuller, who invented a new mathematical system based on these same principles.
The Linux Cookbook: Tips and Techniques for Everyday Use
The invention of new tools has been on the rise along with the increased popularity of Linux-based
systems. At the time of this writing, there were a total of 1,190 tools in the two primary tool directories
(‘/bin’ and ‘/usr/bin’) on my Linux system. These tools, combined with necessary applications,
make free, open source software—for perhaps the first time in its history—a complete, robust system for
general use.
This separation is accomplished by giving each individual user an account on the system. You need
an account in order to use the system; with an account you are issued an individual workspace to use,
and a unique username that identifies you to the system and to other users. It is the name that the system
(and those who use it) will then forever know you as; it’s a single word, in all lowercase letters.
During the installation process, the system administrator should have created an account for you.
(The system administrator has a special account whose username is root; this account has total access
to the entire system, so it is often called the superuser.)
Until the mid-1990s it was widely common for usernames to be the first letter of your first name
followed by your entire surname, up to 12 characters total. So for example, user Samuel Clemens would
have a username of sclemens by this convention; this, however, is not a hard and fast rule, espe-
cially on home systems where you may be the only user. Sometimes, a middle initial may be used
(“dkjohnson”), or sometimes even nicknames or initials are used (“zenboy,” “xibo”). But what-
ever username you pick for yourself, make sure it’s one you can live with, and one you can stand being
called by both the system and other users (your username also becomes part of your email address, as
we’ll see in Chapter 30 [Email], page 275).
In addition to your username, you should also have a password that you can keep secret so that only
you can use your account. Good passwords are strings of text that nobody else is likely to guess (i.e., not
obvious words like ‘secret’, or identifying names like ‘Ruski’, if that happens to be your pet cat).
A good password is one that is highly memorable to you so that you don’t have to write it down, but
is complex enough in construction so that anyone else couldn’t ever guess it. For example, ‘t39sAH’
might be a fine password for someone whose first date was to see the movie The 39 Steps directed by
Alfred Hitchcock.
NOTE: While usernames are always in lowercase, passwords are case sensitive; the passwords
‘Secret’, ‘secret’, and ‘SECRET’ are all considered different.
« ¨
A typical login: prompt looks like this:
ªbardo login: ©
Every Linux system has its own name, called the system’s hostname ; a Linux system is sometimes
called a host, and it identifies itself with its hostname at the login: prompt. It’s important to name your
system—like a username for a user account, a hostname gives name to the system you are using (and it
becomes especially important when putting the system on a network). The system administrator usually
names the system when it is being initially configured (the hostname can always be changed later; its
name is kept in the file ‘/etc/hostname’). Like usernames, hostnames are one word in all lowercase
letters. People usually give their system a name they like, such as darkstar or shiva.
In this example, ‘bardo’ is the hostname of this particular Linux system.
The name of the terminal you are connecting from is displayed just after the hostname. In this
example, the terminal is ‘tty1’, which means that this is the first terminal on this particular system.
(Incidentally, ‘tty’ is short for “teletype,” which historically was the kind of terminal hardware that
most Unix-based systems used by default.)
To log in to the system, type your username (followed by RET) at the login: prompt, and then
type your password when asked (also followed by RET); for security purposes, your password is not
displayed on the screen when you type it.
¯ To log in to the system with a username of ‘kurt’ and a password of ‘empathy’, type:
« ¨
Debian GNU/Linux 2.2 bardo tty1
Most of the programs included with the Debian Linux system are
freely redistributable; the exact distribution terms for each
program are described in the individual files in
/usr/doc/*/copyright
ª˜ $
©
Once you’ve entered your username and password, you are “logged in” to the system. You can then
use the system and run commands.
As soon as you log in, the system displays the contents of ‘/etc/motd’, the “Message of the Day”
file. The system then displays the time and date of your last login, and reports whether or not you have
electronic mail waiting for you (see Chapter 30 [Email], page 275). Finally, the system puts you in a
shell—the environment in which you interact with the system and give it commands. Use of the default
shell on most Linux systems, bash, is discussed in Chapter 3 [The Shell], page 33.
The dollar sign (‘$’) displayed to the left of the cursor is called the shell prompt ; it means that the
system is ready and waiting for input. (You can change this prompt to any text of your liking; to learn
how, see Section 3.6.1 [Changing the Shell Prompt], page 42.) By default, the shell prompt includes the
name of the current directory, which it places to the left of the ‘$’ character. The tilde character (‘˜’), is
a shell symbol that denotes the user’s home directory—when you log in, you are in your home directory
(these terms are defined in Chapter 5 [Files and Directories], page 59).
To end your session on the system, type logout at the shell prompt. This command logs you out of the
system, and a new login: prompt appears on your terminal.
¯ To log out of the system, type:
The Linux Cookbook: Tips and Techniques for Everyday Use
« ¨
$ logout RET
ªbardo login: ©
What works equally well to typing the logout command is to just type C-d (hold down CTRL and
press D). You don’t even have to type RET afterwards. Many users prefer this quick shortcut.
Logging out of the system frees the terminal you were using—and ensures that nobody can access
your account from this terminal.
If you are the only person using your system and have just ended a session by logging out, you might
want to power down the system. See Section 2.1.2 [Shutting Down the System], page 17, earlier in this
chapter.
« ¨
This command switches to the fourth virtual console, denoted by ‘tty4’:
ªbardo login: ©
You can also cycle through the different virtual consoles with the left and right arrow keys. To switch
to the next-lowest virtual console (or wrap around to the highest virtual console, if you’re at the first
virtual console), press ALT-. To switch to the next-highest virtual console, press ALT-.
¯ To switch from the fourth to the third virtual console, press:
ALT-
ªbardo login: ©
The seventh virtual console is reserved for the X Window System. If X is installed, this virtual
terminal will never show a login: prompt, but when you are using X, this is where your X session
appears. If your system is configured to start X immediately, this virtual console will show an X login
screen.
You can switch to a virtual console from the X Window System using CTRL in conjunction with the
usual ALT and function keys. This is the only console manipulation keystroke that works in X.
¯ To switch from X to the first virtual console, press:
CTRL-ALT-F1
ALT- Switch to the next-lowest virtual console. For example, typing this
while in virtual console 4 switches to virtual console 3. Pressing this
keystroke in the lowest console wraps around to the highest console.
ALT- Switch to the next-highest virtual console. For example, typing this
while in virtual console 4 switches to virtual console 5. Pressing this
keystroke in the highest console wraps around to the lowest console.
SHIFT-PgDn When viewing previously displayed text, scroll forward one screen.
The Linux Cookbook: Tips and Techniques for Everyday Use
$ hostname RET
bardo
ª
$
©
The hostname of the system in the example is ‘bardo’.
Options always begin with a hyphen character, ‘-’, which is usually followed by one alphanumeric
character. To include an option in a command, follow the name of the tool or application with the option.
Always separate the tool name, each option, and each argument with a space character.
Long-style options (sometimes called “GNU-style” options) begin with two hyphen characters (‘--’)
and are usually one English word.
For example, many tools have an option, ‘--version’, to output the version number of the tool.
(Many tools also have a ‘--help’ option, which outputs a list of options the tool takes; see Section 2.8.3
[Listing the Usage of a Tool], page 27.)
¯
« ¨
To output the version of the hostname tool, type:
ª
$
©
This command outputs the text ‘hostname 2.10’, indicating that this is version 2.10 of the
hostname tool.
Sometimes, an option itself may may take an argument. For example, hostname has an option for
specifying a file name to use to read the hostname from, ‘-F’; it takes as an argument the name of the
file that hostname should read from.
¯ To run hostname and specify that the file ‘host.info’ is the file to read from, type:
$ hostname -F host.info RET
2.5 Changing Your Password
To change your password, use the passwd tool. It prompts you for your current password and a new
password to replace it with. For security purposes, neither the old nor the new password is echoed to
the screen as you type it. To make sure that you type the new password correctly, passwd prompts you
for your new password twice. You must type it exactly the same way both times, or passwd will not
change your password.
¯
« ¨
To change your password, type:
$ passwd RET
Changing password for kurt
Old password: your current password RET
Enter the new password (minimum of 5, maximum of 8 characters)
Please use a combination of upper and lower case letters and numbers.
New password: your new password RET
Re-enter new password: your new password RET
Password changed.
ª
$
©
NOTE: Passwords can contain uppercase and lowercase letters, the digits 0 through 9, and punctuation
marks; they should be between five and eight characters long. See Section 2.2 [Accounts and Privileges],
page 17, for suggestions on choosing a good password.
$ whoami RET
kurt
ª
$
©
In this example, the username of the user logged in at this terminal is ‘kurt’.
ª
$
©
The output in this example shows that the user murky is logged in on tty1 (the first virtual console
on the system), and has been on since 20:09 on 20 October. The user dave is logged in on tty2
(the second virtual console), and has been on since 14:37 on 21 October. The user kurt is logged in
twice—on tty3 (the third virtual console), and ttyp1, which is an X session with a window location
of ‘(:0.0)’.
NOTE: This command is for listing the users on the local system; to list the users connected to a different
system on the network, or to see more detailed information that a user may have made public about
himself, see Section 32.4.2 [Checking Whether a User Is Online], page 306.
$ w RET
5:27pm up 17:53, 4 users, load average: 0.12, 0.06, 0.01
USER TTY FROM LOGIN IDLE JCPU PCPU WHAT
murky tty1 Oct 20 20:09 17:22m 0.32s 0.32s -bash
dave tty2 14:37 13.00s 2:35 0.07s less foo
kurt tty3 15:04 1:00m 0.41s 0.09s startx
kurt ttyp1 :0.0 15:04 0:00s 21.65s 20.96s emacs
ª$
©
In this example, the command’s output shows that the current system time is 5:27 p.m., the system
has been up for 17 hours and 53 minutes, and there are four users currently logged in: murky is logged
in at tty1, has been idle for 17 hours and 22 minutes, and is at a bash shell prompt; dave is logged in
at tty2, has been idle for 13 seconds, and is using less to peruse a file called ‘foo’ (see Section 9.1
[Perusing Text], page 99); and kurt is logged in at two terminals—tty3 and ttyp1, which is an X
session. He ran the startx command on tty3 to start his X session, and within his X session, he is
currently using Emacs.
$ ps RET
PID TTY STAT TIME COMMAND
193 1 S 0:01 -bash
204 1 S 0:00 ps
ª
$
©
In this example, ps shows that two processes are running: the bash and ps commands.
NOTE: There could be a lot of output—even single-user Linux systems typically have fifty or more
processes running at one time—so you may want to pipe the output of this command through less for
perusal (see Section 9.1 [Perusing Text], page 99).
Additionally, use top to show a display of all processes on the system, sorted by their demand on
the system resources. The display is continually updated with current process information; press Q to
stop the display and exit the program. This tool also displays the information about system runtime and
memory that can be output with the uptime and free commands.
¯ To display a continually updated display of the current system processes, type:
$ top RET
ª$ ©
NOTE: The apropos tool only finds exact matches, so a search for the keyword ‘console’ might not
list the programs that a search for the keyword ‘consoles’ would yield, and vice versa.
Another way to find tools by keyword is to search the system manual pages (see Section 2.8.4 [Read-
ing a Page from the System Manual], page 28). To do this, use man and give the text to search for as an
argument to the ‘-k’ option. This searches the short descriptions and manual page names for the given
text, and outputs a list of those tools that match in the same format as the apropos tool.
¯ To output a list of all tools whose pages in the system manual contain a reference to consoles, type:
$ man -k consoles RET
On Debian systems, yet another way to find installed software by keyword is to use dpkg, the Debian
package tool. Use the ‘-l’ option to list all of the installed packages, which are each output on a line of
their own with their package name and a brief description.
You can output a list of packages that match a keyword by piping the output to grep. Use the ‘-i’
option with grep to match keywords regardless of case (grep is discussed in Chapter 14 [Searching
Text], page 147).
Additionally, you can directly peruse the file ‘/var/lib/dpkg/available’; it lists all available
packages and gives a description of them.
¯ To list all of the packages on the system, type:
$ dpkg -l RET
¯ To list all of the packages whose name or description contains the text “edit,” regardless of case,
type:
$ dpkg -l | grep -i edit RET
Use whatis to list a one-line description of a program. Give the name of the tool or application to list
as an argument.
¯ To get a description of the who tool, type:
$ whatis who RET
NOTE: The whatis tool gets its descriptions from the manual page of a given program; manual pages
are described later in this section, in Section 2.8.4 [Reading a Page from the System Manual], page 28.
Many tools have a long-style option, ‘--help’, that outputs usage information about the tool, including
the options and arguments the tool takes.
¯ To list the possible options for whoami, type:
The Linux Cookbook: Tips and Techniques for Everyday Use
« ¨
$ whoami --help RET
Usage: whoami [OPTION]...
Print the user name associated with the current effective user id.
Same as id -un.
ª$
©
This command outputs some usage information about the whoami tool, including a short description
and a list of possible options.
NOTE: Not all tools take the ‘--help’ option; some tools take a ‘-h’ or ‘-?’ option instead, which
performs the same function.
In the olden days, the hardcopy reference manual that came with most Unix systems also existed elec-
tronically on the system itself; each software program that came with the system had its own manual page
(often called a “man page”) that described it. This is still true on Linux-based systems today, except they
don’t always come with a hardcopy manual.
Use the man tool to view a page in the system manual. As an argument to man, give the name of
the program whose manual page you want to view (so to view the manual page for man, you would type
man man).
$ man w RET
ª ©
Use the up and down arrow keys to move through the text. Press Q to stop viewing the manual
page and exit man. Since man uses less to display the text, you can use any of the less keyboard
commands to peruse the manual page (see Section 9.1 [Perusing Text], page 99).
Despite its name, a manual page does not always contain the complete documentation to a program,
but it’s more like a quick reference. It usually gives a short description of the program, and lists the
options and arguments it takes; some manual pages also include an example or a list of related commands.
(Sometimes, commands have very complete, extensive manual pages, but more often, their complete
documentation is found either in other help files that come with it or in its Info documentation; these are
subjects of the following two recipes.)
To prepare a man page for printing, see Section 25.3.4 [Preparing a Man Page for Printing], page 243.
This command starts info at the system’s Top menu, which shows some of the info key commands
«
and displays a list of available manuals:
¨
ª ©
Use the arrow keys to move through each “page” of information, called an Info node. Nodes are the
base unit of information in Info, and are arranged hierarchically—a manual’s Top node will contain an
Info menu containing links to its various chapters, and a chapter node will contain a menu with links for
its sections, and so on. Links also appear as cross references in the text.
Links look the same in both menu items and cross references: an asterisk (‘*’), the name of the node
it links to, and either one or two colon characters (‘:’). To follow a link to the node it points to, move
the cursor over any part of the node name in the link and press RET.
To run a tutorial that describes how to use info, press the H key. Press Q at any time to stop
reading the documentation and exit info.
To read Info documentation for a tool or application, give its name as an argument to info; if no
Info manual exists for that tool, info displays the man page for that tool instead.
¯ To read the Info documentation for the tar tool, type:
$ info tar RET
This command opens a copy of The GNU tar Manual in info.
To read the contents of a file written in Info format, give the name of the file to read with the
‘-f’ option. This is useful for reading an Info file that you have obtained elsewhere, and is not in
the ‘/usr/info’ directory with the rest of the installed Info files. Info can automatically recognize and
expand Info files that are compressed and have a ‘.gz’ file name extension (see Section 8.5 [Compressed
Files], page 92).
¯ To read ‘faq.info’, an Info file in the current directory, type:
$ info -f faq.info RET
This command starts info and opens the Info file ‘faq.info’, beginning at the top node in the
file.
To read a specific node in an Info file, give the name of the node to use in quotes as an argument to
the ‘-n’ option.
¯ To read ‘faq.info’, an Info file in the current directory, beginning with the node Text, type:
$ info -n ’Text’ -f faq.info RET
NOTE: You can also read Info documentation directly from the Emacs editor; you type C-h i from
Emacs to start the Info reader, and then use the same commands as in the standalone info tool (see
Section 10.2.1 [Getting Acquainted with Emacs], page 109).
The Emacs “incremental” search command, C-s, also works in info; it’s a very fast, efficient way
to search for a word or phrase in an entire Info text (like this entire book); see Section 14.6.1 [Searching
Incrementally in Emacs], page 154.
The ‘/usr/doc’ directory is for miscellaneous documentation: HOWTOs, FAQs, Debian-specific doc-
umentation files and documentation files that come with commands. (To learn more about files and
directories, see Chapter 5 [Files and Directories], page 59.) To peruse any of these files, use less,
described in full in Section 9.1 [Perusing Text], page 99.
When a software package is installed, any additional documentation files it might have beyond a
manual page and Info manual are placed here, in a subdirectory with the name of that package. For
example, additional documentation for the hostname package is in ‘/usr/doc/hostname’, and
documentation for the passwd package is in ‘/usr/doc/passwd’. Most packages have a file called
‘README’, which usually contains relevant information. Often this file is compressed as ‘README.gz’,
in which case you can use zless instead of less.
The Linux Documentation Project (LDP) has overseen the creation of more than 100 “HOWTO”
files, each of which covers a particular aspect of the installation or use of Linux-based systems.
The LDP HOWTOs are compressed text files stored in the ‘/usr/doc/HOWTO’ directory; to view
them, use zless. The file ‘/usr/doc/HOWTO/HOWTO-Index.gz’ contains an annotated index of
all the HOWTO documents installed on the system.
Finally, the ‘/usr/doc/FAQ’ directory contains a number of FAQ (“Frequently Asked
Questions”) files on various subjects, and the files that make up the Debian FAQ are in the
‘/usr/doc/debian/FAQ’ directory. The Debian FAQ is available both in HTML format, which you
can view in a Web browser (see Section 5.9 [Browsing Files], page 73), and as a compressed text file,
which you can view in zless.
¯ To view the HTML version of the Debian FAQ in the lynx Web browser, type:
$ lynx /usr/doc/debian/FAQ/debian-faq.html RET
¯ To view the compressed text version of the Debian FAQ in zless, type:
$ zless /usr/doc/debian/FAQ/debian-faq.txt.gz RET
NOTE: It’s often very useful to use a Web browser to browse through the documentation files in these
directories—see Section 5.9 [Browsing Files], page 73.
On some systems, ‘/usr/doc’ is superseded by the ‘/usr/share/doc’ directory.
LDP documents are available in other formats as well, including HTML and DVI.
The Linux Cookbook: Tips and Techniques for Everyday Use
3 The Shell
The subject of this chapter is the shell, the program that reads your command input and runs the specified
commands. The shell environment is the most fundamental way to interact with the system—you are
said to be “in” a shell from the very moment you’ve successfully logged in to the system.
The ‘$’ character preceding the cursor is called the shell prompt ; it tells you that the system is ready
and waiting for input. On Debian systems, the default shell prompt also includes the name of the current
directory (see Chapter 5 [Files and Directories], page 59). A tilde character (‘˜’) denotes your home
directory, which is where you’ll find yourself when you log in.
« ¨
For example, a typical user’s shell prompt might look like this:
ª˜ $ _ ©
If your shell prompt shows a number sign (‘#’) instead of a ‘$’, this means that you’re logged in
with the superuser, or root, account. Beware: the root account has complete control over the system;
one wrong keystroke and you might accidentally break it something awful. You need to have a different
user account for yourself, and use that account for your regular use (see Section A.3.1 [Making a User
Account], page 318).
Every Linux system has at least one shell program, and most have several. We’ll cover bash, which
is the standard shell on most Linux systems. (Its name stands for “Bourne again shell”—a pun on the
name of Steve Bourne, who was author of the traditional Unix shell, the Bourne shell.)
NOTE: See Info file ‘bashref.info’, node ‘Top’, for more information on using bash.
C-y Yank, or “paste,” the text that was last killed. Text is inserted at the
point where the cursor is.
C-_ Undo the last thing typed on this command line.
Move the cursor to the left one character.
Move the cursor to the right one character.
and Cycle through the command history (see Section 3.4 [Command His-
tory], page 40).
NOTE: These keyboard commands are the same as those used by the Emacs editor (see Section 10.2
[Emacs], page 108). Many other Emacs keyboard commands also work on the command line (see Sec-
tion 10.2.2 [Basic Emacs Editing Keys], page 111). And, for Vi aficionados, it is possible to configure
bash to recognize Vi-style bindings instead.
The following sections describe some important features of command line editing, such as quoting
special characters and strings, letting the shell complete your typing, re-running commands, and running
multiple commands. See Info file ‘bashref.info’, node ‘Command Line Editing’ for more in-
formation on bash’s command line editing features.
The key moves the last command you typed back to the input line, and RET executes it.
By typing more than once, you can go back to earlier commands you’ve typed; this is a function
of your command history, which is explained in full in Section 3.4 [Command History], page 40.
Additionally, you can use the bash reverse-incremental search feature, C-r, to search, in reverse,
through your command history. You’ll find this useful if you remember typing a command line with
‘foo’ in it recently, and you wish to repeat the command without having to retype it. Type C-r followed
by the text foo, and the last command you typed containing ‘foo’ appears on the input line.
Like the Emacs command of the same name (see Section 14.6.1 [Searching Incrementally in Emacs],
page 154), this is called an incremental search because it builds the search string in character increments
The Unix way of saying it is that the command “rings the system bell.”
The Linux Cookbook: Tips and Techniques for Everyday Use
as you type. Typing the string ‘cat’ will first search for (and display) the last input line containing a
‘c’, then ‘ca’, and finally ‘cat’, as you type the individual characters of the search string. Typing C-r
again retrieves the next previous command line that has a match for the search string.
¯ To put the last command you entered containing the string ‘grep’ back on the input line, type:
$ C-r
(reverse-i-search)‘’: grep
¯ To put the third-to-the-last command you entered containing the string grep back on the input line,
type:
$ C-r
(reverse-i-search)‘’: grep
C-r C-r
When a command is displayed on the input line, type RET to run it. You can also edit the command
line as usual.
ª$
©
3.2 Redirecting Input and Output
The shell moves text in designated “streams.” The standard output is where the shell streams the text out-
put of commands—the screen on your terminal, by default. The standard input, typically the keyboard, is
where you input data for commands. When a command reads the standard input, it usually keeps reading
text until you type C-d on a new line by itself.
When a command runs and exits with an error, the error message is usually output to your screen, but
as a separate stream called the standard error.
You redirect these streams—to a file, or even another command—with redirection. The following
sections describe the shell redirection operators that you can use to redirect standard input and output.
Type C-z to suspend or stop the foreground job—useful for when you want to do something else in the
shell and return to the current job later. The job stops until you either bring it back to the foreground
or make it run in the background (see Section 3.3.3 [Putting a Job in the Foreground], page 39 and see
Section 3.3.2 [Putting a Job in the Background], page 38).
For example, if you are reading a document in info, typing C-z will suspend the info program
and return you to a shell prompt where you can do something else (see Section 2.8.5 [Using the GNU
Info System], page 29). The shell outputs a line giving the job number (in brackets) of the suspended
job, the text ‘Stopped’ to indicate that the job has stopped, and the command line itself, as shown here:
[1]+ Stopped info -f cookbook.info
In this example, the job number is 1 and the command that has stopped is ‘info -f
cookbook.info’. The ‘+’ character next to the job number indicates that this is the most recent job.
If you have any stopped jobs when you log out, the shell will tell you this instead of logging you out:
« ¨
$ logout RET
There are stopped jobs.
ª$
©
At this point you can list your jobs (see Section 3.3.4 [Listing Your Jobs], page 39), stop any jobs you
have running (see Section 3.3.5 [Stopping a Job], page 39), and then log out.
New jobs run in the foreground unless you specify otherwise. To run a job in the background, end the
input line with an ampersand (‘&’). This is useful for running non-interactive programs that perform a
lot of calculations.
¯ To run the command apropos shell > shell-commands as a background job, type:
« ¨
$ apropos shell > shell-commands & RET
[1] 6575
ª$
©
The shell outputs the job number (in this case, 1) and process ID (in this case, 6575), and then returns
to a shell prompt. When the background job finishes, the shell will list the job number, the command,
and the text ‘Done’, indicating that the job has completed successfully:
[1]+ Done apropos shell >shell-commands
To move a job from the foreground to the background, first suspend it (see Section 3.3.1 [Suspending
a Job], page 38) and then type bg (for “background”).
¯ For example, to start the command apropos shell > shell-commands in the foreground,
suspend it, and then specify that it finish in the background, you would type:
« ¨
$ apropos shell > shell-commands RET
C-z
ª
$
©
If you have suspended multiple jobs, specify the job to be put in the background by giving its job
number as an argument.
¯ To run job 4 in the background, type:
$ bg %4 RET
NOTE: Running a job in the background is sometimes called “backgrounding” or “amping off” a job.
$ jobs RET
[1]- Stopped apropos shell >shell-commands
[2]+ Stopped apropos bash >bash-commands
ª
$
©
This example shows two jobs—apropos shell > shell-commands and apropos bash >
bash-commands. The ‘+’ character next to a job number indicates that it’s the most recent job, and
the ‘-’ character indicates that it’s the job previous to the most recent job. If you have no current jobs,
jobs returns nothing.
To list all of the processes you have running on the system, use ps instead of jobs—see Section 2.7
[Listing System Activity], page 25.
ª$
©
Use kill to interrupt (“kill”) a background job, specifying the job number as an argument.
¯ To kill job number 2, type:
$ kill %2 RET
$ history RET
1 who
2 apropos shell >shell-commands
3 apropos bash >bash-commands
4 history
ª$
©
This command shows the contents of your command history file, listing one command per line pref-
aced by its event number. Use an event number to specify that event in your history (see Section 3.4.2
[Specifying a Command from Your History], page 41).
If your history is a long one, this list will scroll off the screen, in which case you may want to pipe the
output to less in order to peruse it. It’s also common to search for a past command by piping the output
to grep (see Section 3.2.4 [Redirecting Output to Another Command’s Input], page 37 and Section 14.1
[Searching for a Word or Phrase], page 147).
¯
« ¨
To search your history for the text ‘apropos’, type:
ª$
©
This command will show the events from your history containing the text ‘apropos’. (The last line
of output is the command you just typed.)
To run a history event by its event number, enter an exclamation point (‘!’, sometimes called “bang”)
followed by the event number. (Get the event number by viewing your history; see Section 3.4.1 [Viewing
Your Command History], page 40).
¯ To run history event number 1, type:
$ !1 RET
ª$
©
In this example, the typescript records a shell session consisting of two commands (hostname and
apropos) to a file called ‘log.19990817’. The typescript looks like this:
Script started on Tue May 25 14:21:52 1999
$ hostname
erie
$ apropos bash > bash.commands
$ exit
exit
NOTE: It’s possible, but usually not desirable, to run script from within another script session.
This usually happens when you’ve forgotten that you are running it, and you run it again inside the
current typescript, even multiple times—as a result, you may end up with multiple sessions “nested”
inside each other like a set of Russian dolls.
« ¨
‘$’ character—type:
$ PS1=’\w $ ’ RET
ª˜ $
©
The following table lists some special characters and their text output at the shell prompt.
S PECIAL C HARACTER T EXT O UTPUT
\a Inserts a C-g character, which makes the internal speaker beep. (It
“rings the system bell”; C-g is sometimes called the bell character.)
\d The current date.
\h The hostname of the system.
\n A newline character.
\t The current system time, in 24-hour format.
\@ The current system time, in 12-hour a.m./p.m. format.
\w The current working directory.
\u Your username.
\! The history number of this command.
You can combine any number of these special characters with regular characters when creating a
value for PS1.
¯ To change the prompt to the current date followed by a space character, the hostname of the system
in parenthesis, and a greater-than character, type:
$ PS1=’\d (\h)>’ RET
14 Dec 1999 (ithaca)>
For all new shells after you’ve logged in (that is, all but the “login shell”), bash reads and executes
the commands in the ‘.bashrc’ file in your home directory. Commands in this file run whenever a new
shell is started except for the login shell.
There are separate configuration files for login and all other shells so that you can put specific cus-
tomizations in your ‘.bash_profile’ that only run when you first log in to the system. To avoid
having to put commands in both files when you want to run the same ones for all shells, append the
following to the end of your ‘.bash_profile’ file:
if [ -f ˜/.bashrc ]; then . ˜/.bashrc; fi
This makes bash run the ‘.bashrc’ file in your home directory when you log in. In this way, you
can put all of your customizations in your ‘.bashrc’ file, and they will be run both at log in and for all
subsequent shells. Any customizations before this line in ‘.bash_profile’ run only when you log
in.
For example, a simple ‘.bash_profile’ might look like this:
# "Comment" lines in shell scripts begin with a # character.
# They are not executed by bash, but exist so that you may
# document your file.
The X Window System, commonly called “X,” is a graphical windowing interface that comes with all
popular Linux distributions. X is available for many Unix-based operating systems; the version of X
that runs on Linux systems with x86-based CPUs is called “XFree86.” The current version of X is 11,
Revision 6—or “X11R6.”
All the command-line tools and most of the applications that you can run in the console can run in X;
also available are numerous applications written specifically for X.
This chapter shows you how to get around in X: how to start it and stop it, run programs within it,
manipulate windows, and customize X to your liking. See The Linux XFree86 HOWTO for information
on installing X (see Section 2.8.6 [Reading System Documentation and Help Files], page 31).
4.1 Running X
WWW: http://www.afterstep.org/
WWW: http://www.fvwm.org/
WWW: http://www.windowmaker.org/
WWW: http://www.gnome.org/
WWW: http://www.kde.org/
When you start X, you should see a mouse pointer appear on the screen as a large, black “X.” If your X
is configured to start any tools or applications, they should each start and appear in individual windows.
A typical X session looks like this:
The root window is the background behind all of the other windows. It is usually set to a color, but
you can change it (see Section 4.6.3 [Changing the Root Window Parameters], page 55). Each program
or application in X runs in its own window. Each window has a decorative border on all four sides,
Sometimes you might see it referred to as “X Windows,” but this term is incorrect.
The Linux Cookbook: Tips and Techniques for Everyday Use
called the window border ; L-shaped corners, called frames ; a top window bar, called the title bar, which
displays the name of the window; and several title bar buttons on the left and right sides of the title bar
(described in Section 4.3 [Manipulating X Client Windows], page 52).
The entire visible work area, including the root window and any other windows, is called the desktop.
The box in the lower right-hand corner, called the pager, allows you to move about a large desktop (see
Section 4.4 [Moving around the Desktop], page 53).
A window manager controls the way windows look and are displayed—the window dressing, as it
were—and can provide some additional menu or program management capabilities. There are many
different window managers to choose from, with a variety of features and capabilities. (See Section 4.6.4
[Choosing a Window Manager], page 56, for help in choosing a window manager that’s right for you.)
Window managers typically allow you to customize the colors and borders that are used to display a
window, as well as the type and location of buttons that appear on the window (see Section 4.2 [Running
a Program in X], page 49). For example, in the image above, the clock image itself is the oclock
program; the blue outline around it is the window border, as drawn by the fvwm2 window manager.
With the afterstep window manager, the window border would look quite different:
There are many window managers you can choose from, all different; instead of describing only one,
or describing all of them only superficially, this chapter shows the basics of X, which are common to all
window managers. I try to make no assumptions as to which window manager you are using; while the
fvwm family of window managers has long been a popular choice on most Linux-based systems, today
other window managers—including WindowMaker (the binary itself is called wmaker), Enlightenment,
AfterStep, and others—have all gained in popularity.
And recently, desktop environments have become popular. These are a collection of applications that
run on top of the window manager (and X), with the purpose of giving your X session a standardized
“look and feel”; these suites normally come with a few basic tools such as clocks and file managers. The
two popular ones are GNOME and KDE, and while they generate a lot of press these days because of
their graphical nature, both are changing very quickly and at the time of this writing are not yet ready for
widespread, general use (and they can cause your system to crash).
If you have a recent Linux distribution and chose the default install, chances are good that you have
either GNOME or KDE installed, with either the fvwm2 or wmaker window manager assigned as the
default. (While you can have more than one window manager installed on your system, you can only run
one at a time.)
4.1.1 Starting X
There are two ways to start X. Some systems run the X Display Manager, xdm, when the system boots, at
which point a graphical xdm login screen appears; you can use this to log in directly to an X session. On
systems not running xdm, the virtual console reserved for X will be blank until you start X by running
the startx command.
¯ To start X from a virtual console, type:
$ startx RET
¯ To run startx and redirect its output to a log file, type:
$ startx >$HOME/startx.log 2>&1 RET
Both of these examples start X on the seventh virtual console, regardless of which console you are
at when you run the command—your console switches to X automatically. You can always switch to
another console during your X session (see Section 2.3 [Console Basics], page 20). The second example
writes any error messages or output of startx to a file called ‘startx.log’ in your home directory.
On some systems, X starts with 8-bit color depth by default. Use startx with the special ‘-bpp’
option to specify the color depth. Follow the option with a number indicating the color depth to use, and
precede the option with two hyphen characters (‘--’), which tells startx to pass the options which
follow it to the X server itself.
¯ To start X from a virtual console, and specify 16-bit color depth, type:
$ startx -- -bpp 16 RET
NOTE: If your system runs xdm, you can always switch to the seventh virtual console (or whichever
console xdm is running on), and then log in at the xdm login screen.
4.1.2 Stopping X
To end an X session, you normally choose an exit X option from a menu in your window manager.
¯ To end your X session if you are running the fvwm2 window manager, click the left mouse button in
the root window to pull up the start menu, and then choose Really quit? from the Exit Fvwm
submenu.
¯ To end your X session if you are running the afterstep window manager, click the left mouse
button in the root window to pull up the start menu, and then choose Really quit? from the
Exit Fvwm submenu.
If you started your X session with startx, these commands will return you to a shell prompt in
the virtual console where the command was typed. If, on the other hand, you started your X session by
logging in to xdm on the seventh virtual console, you will be logged out of the X session and the xdm
login screen will appear; you can then switch to another virtual console or log in to X again.
To exit X immediately and terminate all X processes, press the CTRL-ALT-BKSP combination (if
your keyboard has two ALT and CTRL keys, press the left ones). You’ll lose any unsaved application
data, but this is useful when you cannot exit your X session normally—in the case of a system freeze or
other problem.
¯ To exit X immediately, type:
CTRL-ALT-BKSP
menus and on ‘Xclock (analog)’. This starts the xclock client, specifying the option to display
an analog face:
You can also start a client by running it from a shell window—useful for starting a client that isn’t on
the menu, or for when you want to specify options or arguments. When you run an X client from a shell
window, it opens in its own window; run the client in the background to free the shell prompt in the shell
window (see Section 3.3.2 [Putting a Job in the Background], page 38).
¯ To run a digital clock from a shell window, type:
$ xclock -digital & RET
This command runs xclock in the background from a shell window; the ‘digital’ option speci-
fies a digital clock.
The following sections explain how to specify certain command-line options common to most X
clients—such as window layout, colors, and fonts.
Or, to put it all together, you can specify the size and location of a window with one geometry line
that includes all four values.
¯ To start an xclock with a width of 120 pixels, a height of 100 pixels, an x offset of 250 pixels from
the right side of the screen, and a y offset of 25 pixels from the top of the screen, type:
$ xclock -geometry 120x100-250+25 RET
NOTE: If you specify the font for a shell window, you can resize it after it’s running, as described in
Section 16.1.4 [Resizing the Xterm Font], page 177.
In the preceding illustration, the current desktop is the second one in the top row. The first desktop
contains two X client windows—a small one and a large one—but there are no windows in any other
desktop (including the current one).
To switch to another desktop, click the left mouse button on its corresponding view in the pager, or use
a keyboard shortcut. In fvwm2, the default keys for switching between desktops areALT in conjunction
with the arrow keys; in afterstep, use the CTRL key in place of ALT.
The Linux Cookbook: Tips and Techniques for Everyday Use
¯ To switch to the desktop to the left of the current one while running fvw2, type ALT-.
¯ To switch to the desktop directly to the left of the current one while running afterstep, type
CTRL-.
4.6 Configuring X
There are some aspects of X that people usually want to configure right away. This section discusses some
of the most popular, including changing the video mode, automatically running clients at startup, and
choosing a window manager. You’ll find more information on this subject in both The X Window User
HOWTO and The Configuration HOWTO (for how to read them, see Section 2.8.6 [Reading System
Documentation and Help Files], page 31).
Type either of the above key combinations repeatedly to cycle through all available modes.
NOTE: For more information on video modes, see The XFree86 Video Timings HOWTO (see Sec-
tion 2.8.6 [Reading System Documentation and Help Files], page 31).
4.6.2 Running X Clients Automatically
The ‘.xsession’ file, a hidden file in your home directory, specifies the clients that are automati-
cally run when your X session first starts (“hidden” files are explained in Chapter 5 [Files and Direc-
tories], page 59). It is just a shell script, usually containing a list of clients to run. You can edit your
‘.xsession’ file in a text editor, and if this file doesn’t exist, you can create it.
Clients start in the order in which they are listed, and the last line should specify the window manager
to use. The following example ‘.xsession’ file starts an xterm with a black background and white
text, puts an ‘oclock’ (a round clock) window in the upper left-hand corner, starts the Emacs text editor,
and then starts the fvwm2 window manager:
#! /bin/sh
#
# A sample .xsession file.
NOTE: You can also put an image in the window (although this consumes memory that could be spared
for a memory-hogging Web browser instead; but see Section 17.2.2 [Putting an Image in the Root Win-
dow], page 186, for how to do it).
dict
bin
usr
jon
play
work
joe
home
bin
etc
(root)
To represent a directory’s place in the file hierarchy, specify all of the directories between it and the
root directory, using a slash (‘/’) as the delimiter to separate directories. So the directory ‘dict’ as it
appears in the preceding illustration would be represented as ‘/usr/dict’.
Each user has a branch in the ‘/home’ directory for their own files, called their home directory. The
hierarchy in the previous illustration has two home directories: ‘joe’ and ‘jon’, both subdirectories of
‘/home’.
When you are in a shell, you are always in a directory on the system, and that directory is called
the current working directory. When you first log in to the system, your home directory is the current
working directory.
Whenever specifying a file name as an argument to a tool or application, you can give the slash-
delimited path name relative to the current working directory. For example, if ‘/home/joe’ is
the current working directory, you can use work to specify the directory ‘/home/joe/work’, and
work/schedule to specify ‘schedule’, a file in the ‘/home/joe/work’ directory.
Every directory has two special files whose names consist of one and two periods: ‘..’ refers to
the parent of the current working directory, and ‘.’ refers to the current working directory itself. If
the current working directory is ‘/home/joe’, you can use ‘.’ to specify ‘/home/joe’ and ‘..’ to
specify ‘/home’. Furthermore, you can specify the ‘/home/jon’ directory as ../jon.
The Linux Cookbook: Tips and Techniques for Everyday Use
Another way to specify a file name is to specify a slash-delimited list of all of the directory branches
from the root directory (‘/’) down to the file to specify. This unique, specific path from the root directory
to a file is called the file’s full path name. (When referring to a file that is not a directory, this is sometimes
called the absolute file name ).
You can specify any file or directory on the system by giving its full path name. A file can have the
same name as other files in different directories on the system, but no two files or directories can share
a full path name. For example, user joe can have a file ‘schedule’ in his ‘/home/joe/work’
directory and a file ‘schedule’ in his ‘/home/joe/play’ directory. While both files have the same
name (‘schedule’), they are contained in different directories, and each has a unique full path name—
‘/home/joe/work/schedule’ and ‘/home/joe/play/schedule’.
However, you don’t have to type the full path name of a tool or application in order to start it. The
shell keeps a list of directories, called the path, where it searches for programs. If a program is “in your
path,” or in one of these directories, you can run it simply by typing its name.
By default, the path includes ‘/bin’ and ‘/usr/bin’. For example, the who command is in the
‘/usr/bin’ directory, so its full path name is /usr/bin/who. Since the ‘/usr/bin’ directory is
in the path, you can type who to run /usr/bin/who, no matter what the current working directory is.
The following table describes some of the standard directories on Linux systems.
D IRECTORY D ESCRIPTION
/ The ancestor of all directories on the system; all other directories are
subdirectories of this directory, either directly or through other subdi-
rectories.
/bin Essential tools and other programs (or binaries).
/dev Files representing the system’s various hardware devices. For example,
you use the file ‘/dev/cdrom’ to access the CD-ROM drive.
/etc Miscellaneous system configuration files, startup files, etcetera.
/home The home directories for all of the system’s users.
/lib Essential system library files used by tools in ‘/bin’.
/proc Files that give information about current system processes.
/root The superuser’s home directory, whose username is root. (In the
past, the home directory for the superuser was simply ‘/’; later,
‘/root’ was adopted for this purpose to reduce clutter in ‘/’.)
/sbin Essential system administrator tools, or system binaries.
/tmp Temporary files.
/usr Subdirectories with files related to user tools and applications.
/usr/X11R6 Files relating to the X Window System, including those programs (in
‘/usr/X11R6/bin’) that run only under X.
/usr/bin Tools and applications for users.
/usr/dict Dictionaries and word lists (slowly being outmoded by
‘/usr/share/dict’).
/usr/doc Miscellaneous system documentation.
/usr/games Games and amusements.
/usr/info Files for the GNU Info hypertext system.
/usr/lib Libraries used by tools in ‘/usr/bin’.
/usr/local Local files—files unique to the individual system—including lo-
cal documentation (in ‘/usr/local/doc’) and programs (in
‘/usr/local/bin’).
/usr/man The online manuals, which are read with the man command (see Sec-
tion 2.8.4 [Reading a Page from the System Manual], page 28).
/usr/share Data for installed applications that is architecture-independent and can
be shared between systems. A number of subdirectories with equiv-
alents in ‘/usr’ also appear here, including ‘/usr/share/doc’,
‘/usr/share/info’, and ‘/usr/share/icons’.
/usr/src Program source code for software compiled on the system.
/usr/tmp Another directory for temporary files.
/var Variable data files, such as spool queues and log files.
NOTE: For more information on the directory structure of Linux-based systems, view the compressed
files in the ‘/usr/doc/debian-policy/fsstnd/’ directory (see Section 9.1 [Perusing Text],
page 99).
$ pwd RET
/home/mrs
ª$
©
In this example, pwd output the text ‘/home/mrs’, indicating that the current working directory is
‘/home/mrs’.
Use ls to list the contents of a directory. It takes as arguments the names of the directories to list. With
no arguments, ls lists the contents of the current working directory.
¯
« ¨
To list the contents of the current working directory, type:
$ ls RET
apple cherry orange
ª$
©
In this example, the current working directory contains three files: ‘apple’, ‘cherry’, and
‘orange’.
¯ To list the contents of ‘work’, a subdirectory in the current directory, type:
$ ls work RET
¯ To list the contents of the ‘/usr/doc’ directory, type:
The Linux Cookbook: Tips and Techniques for Everyday Use
$ ls /usr/doc RET
You cannot discern file types from the default listing; directories and executables are indistinguishable
from all other files. Using the ‘-F’ option, however, tells ls to place a ‘/’ character after the names of
subdirectories and a ‘*’ character after the names of executable files.
¯ To list the contents of the directory so that directories and executables are distinguished from other
« ¨
files, type:
$ ls -F RET
repeat* test1 test2 words/
ª
$
©
In this example, the current directory contains an executable file named ‘repeat’, a directory named
‘words’, and some other files named ‘test1’ and ‘test2’.
Another way to list the contents of directories—and one I use all the time, when I’m in X and when
I also want to look at image files in those directories—is to use Mozilla or some other Web browser
as a local file browser. Use the prefix file:/ to view local files. Alone, it opens a directory list-
ing of the root directory; file:/home/joe opens a directory listing of user joe’s home directory,
file:/usr/local/src opens the local source code directory, and so on. Directory listings will be
rendered in HTML on the fly in almost all browsers, so you can click on subdirectories to traverse to
them, and click on files to open them in the browser.
Yet another way to list the contents of directories is to use a “file manager” tool, of which there are at
least a few on Linux; the most popular of these is probably the “Midnight Commander,” or mc.
The following subsections describe some commonly used options for controlling which files ls lists
and what information about those files ls outputs. It is one of the most often used file commands on
Unix-like systems.
$ ls -l /usr/doc/bash RET
total 72
-rw-r--r-- 1 root root 13744 Oct 19 22:57 CHANGES.gz
-rw-r--r-- 1 root root 1816 Oct 19 22:57 COMPAT.gz
-rw-r--r-- 1 root root 16398 Oct 19 22:57 FAQ.gz
-rw-r--r-- 1 root root 2928 Oct 19 22:57 INTRO.gz
-rw-r--r-- 1 root root 4751 Oct 19 22:57 NEWS.gz
-rw-r--r-- 1 root root 1588 Oct 19 22:57 POSIX.NOTES.gz
-rw-r--r-- 1 root root 2718 Oct 19 22:57 README.Debian.gz
-rw-r--r-- 1 root root 19596 Oct 19 22:57 changelog.gz
-rw-r--r-- 1 root root 1446 Oct 19 22:57 copyright
drwxr-xr-x 9 root root 1024 Jul 25 1997 examples
ª$
©
Called a URN, or “Uniform Resource Name.”
This command outputs a verbose listing of the files in ‘/usr/doc/bash’. The first line of output
gives the total amount of disk space, in 1024-byte blocks, that the files take up (in this example, 72).
Each subsequent line displays several columns of information about one file.
The first column displays the file’s type and permissions. The first character in this column specifies
the file type; the hyphen (‘-’) is the default and means that the file is a regular file. Directories are denoted
by ‘d’, and symbolic links (see Section 5.7 [Giving a File More than One Name], page 71) are denoted
by ‘l’. The remaining nine characters of the first column show the file permissions (see Section 6.3
[Controlling Access to Files], page 76). The second column lists the number of hard links to the file. The
third and fourth columns give the names of the user and group that the file belongs to. The fifth column
gives the size of the file in bytes, the sixth column gives the date and time of last modification, and the
last column gives the file name.
$ ls -R RET
play work
play:
notes
work:
notes
ª$
©
In this example, the current working directory contains two subdirectories, ‘work’ and ‘play’, and
no other files. Each subdirectory contains a file called ‘notes’.
¯ To list all of the files on the system, type:
$ ls -R / RET
This command recursively lists the contents of the root directory, ‘/’, and all of its subdirectories. It
is common to combine this with the attribute option, ‘-l’, to output a verbose listing of all the files on
the system:
$ ls -lR / RET
NOTE: You can’t list the contents of some directories on the system if you don’t have permission to do
so (see Section 6.3 [Controlling Access to Files], page 76).
period; these are called dot files, or sometimes “hidden” files. As mentioned earlier, every directory has
two special dot files: ‘..’, the parent directory, and ‘.’, the directory itself.
To list all contents of a directory, including these dot files, use the ‘-a’ option.
Use the ‘-A’ option to list almost all files in the directory: it lists all files, including dot files, with the
exception of ‘..’ and ‘.’.
¯ To list all files in the current directory except for ‘..’ and ‘.’, type:
$ ls -A RET
Use ls with the ‘--color’ option to list the directory contents in color; files appear in different colors
depending on their content. Some of the default color settings include displaying directory names in
blue, text files in white, executable files in green, and links in turquoise.
¯ To
« list the files in the root directory in color, type: ¨
ª ©
NOTE: It’s common practice to create a command alias that substitutes ‘ls --color’ for ‘ls’, so that
typing just ls outputs a color listing. To learn more about making aliases, see Section 3.6.2 [Making a
Command Alias], page 43.
Debian: ‘tree’
WWW: ftp://mama.indstate.edu/linux/tree/
Use tree to output an ASCII text tree graph of a given directory tree.
¯ To output a tree graph of the current directory and all its subdirectories, type:
« ¨
$ tree RET
.
|-- projects
| |-- current
| ‘-- old
| |-- 1
| ‘-- 2
‘-- trip
‘-- schedule.txt
4 directories, 3 files
ª$
©
In the preceding example, a tree graph is drawn showing the current directory, which contains the
two directories ‘projects’ and ‘trip’; the ‘projects’ directory in turn contains the directories
‘current’ and ‘old’.
To output a tree graph of a specific directory tree, give the name of that directory tree as an argument.
¯ To output a tree graph of your home directory and all its subdirectories, type:
$ tree ˜ RET
To output a graph of a directory tree containing directory names only, use the ‘-d’ option. This is
useful for outputting a directory tree of the entire system, or for getting a picture of a particular directory
tree.
¯ To output a tree graph of the entire system to the file ‘tree’, type:
$ tree -d / > tree RET
¯ To peruse a tree graph of the ‘/usr/local’ directory tree, type:
$ tree -d /usr/local |less RET
NOTE: Another tool for outputting directory trees is described in Section 24.2 [Listing a File’s Disk
Usage], page 233.
NOTE: You can combine any of these options; for example, to list the contents of a directory sorted
newest first, and display all attributes, use ‘-lt’. To recursively list all hidden files and display all
attributes, use ‘-lRa’. It doesn’t matter what order you put the options in—so ‘-lRa’ is the same as,
say, ‘-alR’.
To change the uppercase letters in a file name to lowercase (or vice versa), use chcase. It takes as
arguments the files whose names it should change.
¯ To change the file names of all of the files in the current directory to lowercase letters, type:
$ chcase * RET
Use the ‘-u’ option to change file names to all uppercase letters.
¯ To change file names of all of the files with a ‘.dos’ extension in the ‘˜/tmp’ directory to all
uppercase letters, type:
$ chcase -u ˜/tmp/*.dos RET
By default, chcase does not rename directories; use the ‘-d’ option to rename directories as well
as other files. The ‘-r’ option recursively descends into any subdirectories and renames those files, too.
¯ To change all of the files and subdirectory names in the current directory to all lowercase letters,
type:
$ chcase -d * RET
¯ To change all of the files and subdirectory names in the current directory to all uppercase letters,
and descend recursively into all subdirectories, type:
$ chcase -d -r -u * RET
¯ To change all of the files in the current directory to all lowercase letters, and descend recursively
into all subdirectories (but do not change any directory names), type:
$ chcase -r * RET
To give a different file name extension to a group of files that share the same file name extension, use
chcase with the ‘-x’ option for specifying a Perl expression; give the patterns to match the source and
target files as a quoted argument.
For example, you can rename all file names ending in ‘.htm’ to end in ‘.html’ by giving
‘s/htm/html/’ as the expression to use.
The Linux Cookbook: Tips and Techniques for Everyday Use
¯ To rename all of the files in the current directory with a ‘.htm’ extension to ‘.html’, type:
$ chcase -x ’s/htm/html/’ ’*.htm’ RET
By default, chcase will not overwrite files; so if you want to rename ‘index.htm’ to
‘index.html’, and both files already exist in the current directory, the above example will do nothing.
Use the ‘-o’ option to specify that existing files may be overwritten.
¯ To rename all of the files in the current directory with a ‘.htm’ extension to ‘.html’ and overwrite
any existing files, type:
$ chcase -o -x ’s/htm/html/’ ’*.htm’ RET
$ rm -i ?cat RET
rm: remove ‘ˆAcat’? y RET
ª$
©
In the above example, the expansion pattern ‘?cat’ matches the file ‘ˆAcat’ and no other files in
the directory. The ‘-i’ option was used because, in some cases, no unique pattern can be made for a
file—for example, if this directory also contained a file called ‘1cat’, the above rm command would
also attempt to remove it; with the ‘-i’ option, you can answer n to it.
These first two methods will not work with files that begin with a hyphen character, because rm will
interpret such a file name as an option; to remove such a file, use the ‘--’ option—it specifies that what
follows are arguments and not options.
¯ To remove the file ‘-cat’ from the current directory, type:
$ rm -- -cat RET
Once a file is removed, it is permanently deleted and there is no command you can use to restore it; you
cannot “undelete” it. (Although if you can unmount the filesystem that contained the file immediately
after you deleted the file, a wizard might be able to help reconstruct the lost file by using grep to search
the filesystem device file.)
A safer way to remove files is to use del, which is simply an alias to rm with the ‘-i’ option. This
specifies for rm to run in interactive mode and confirm the deletion of each file. It may be good practice
to get in the habit of using del all the time, so that you don’t make an accidental slip and rm an important
file.
NOTE: Question 3.6 in the Unix FAQ (see ‘/usr/doc/FAQ/unix-faq-part3’) discusses this
issue, and gives a shell script called can that you can use in place of rm—it puts files in a “trashcan”
directory instead of removing them; you then periodically empty out the trashcan with rm.
After running this command, you can read and edit ‘emerald-city’; any changes you make
to ‘emerald-city’ will be written to ‘seattle’ (and vice versa). But if you remove the file
‘emerald-city’, the file ‘seattle’ will not be removed.
$ groups RET
steward galley crew
ª$
©
In this example, three groups are output: steward (the user’s login group), galley, and crew.
¯
« ¨
To list the group memberships of user blackbeard, type:
ª$
©
In this example, the command outputs the given username, blackbeard, followed by the name
of one group, blackbeard, indicating that user blackbeard belongs to only one group: his login
group.
To list the members of a particular group, use the members tool, giving the name of the particular group
as an argument.
¯ To output a list of the members of the galley group, type:
The Linux Cookbook: Tips and Techniques for Everyday Use
« ¨
$ members galley RET
captain steward pete
ª$
©
In this example, three usernames are output, indicating that these three users are the members of the
galley group.
¯ To list all files on the system whose file name is ‘top’, regardless of case, type:
$ find / -iname top RET
This command would match any files whose name consisted of the letters ‘top’, regardless of case—
including ‘Top’, ‘top’, and ‘TOP’.
Use file expansion characters (see Section 5.8 [Specifying File Names with Patterns], page 72) to find
files whose names match a pattern. Give these file name patterns between single quotes.
¯ To list all files on the system whose names begin with the characters ‘top’, type:
$ find / -name ’top*’ RET
¯ To list all files whose names begin with the three characters ‘top’ followed by exactly three more
characters, type:
$ find / -name ’top???’ RET
¯ To list all files whose names begin with the three characters ‘top’ followed by five or more charac-
ters, type:
$ find / -name ’top?????*’ RET
¯ To list all files in your home directory tree that end in ‘.tex’, regardless of case, type:
$ find ˜ -iname ’*.tex’ RET
¯ To list all files in the ‘/usr/share’ directory tree with the text ‘farm’ somewhere in their name,
type:
$ find /usr/share -name ’*farm*’ RET
Use ‘-regex’ in place of ‘-name’ to search for files whose names match a regular expression, or
a pattern describing a set of strings (see Section 14.2 [Regular Expressions—Matching Text Patterns],
page 148).
¯ To list all files in the current directory tree whose names have either the string ‘net’ or ‘comm’
anywhere in their file names, type:
$ find . -regex ’.*\(net\|comm\).*’ RET
NOTE: The ‘-regex’ option matches the whole path name, relative to the directory tree you specify,
and not just file names.
$ ls | wc -l RET
19
ª
$
©
In this example, the command outputs the text ‘19’, indicating that there are 19 files in the current
directory.
Since ls does not list hidden files by default (see Section 5.3.4 [Listing Hidden Files], page 65), the
preceding command does not count them. Use ls’s ‘-A’ option to count dot files as well.
¯
« ¨
To count the number of files—including dot files—in the current directory, type:
$ ls -A | wc -l RET
81
ª
$
©
This command outputs the text ‘81’, indicating that there are 81 files, including hidden files, in the
current directory.
To list the number of files in a given directory tree, and not just a single directory, use find instead
of ls, giving the special find predicate ‘\! -type d’ to exclude the listing (and therefore, counting)
of directories.
The Linux Cookbook: Tips and Techniques for Everyday Use
ª/usr/bin/perl
©
In this example, which output ‘/usr/bin/perl’, indicating that the perl binary is installed in
the ‘/usr/bin’ directory.
NOTE: This is also useful for determining “which” binary would execute, should you type the name,
since some systems may have different binaries of the same file name located in different directories. In
that case, you can use which to find which one would execute.
8 Managing Files
File management tools include those for splitting, comparing, and compressing files, making backup
archives, and tracking file revisions. Other management tools exist for determining the contents of a file,
and for changing its timestamp.
ª$
©
This command reports that the file ‘/usr/doc/HOWTO/README.gz’ contains data that has been
compressed with the gzip tool.
To determine the original format of the data in a compressed file, use the ‘-z’ option.
¯ To determine the format of the compressed data contained in the file
« ¨
‘/usr/doc/HOWTO/README.gz’, type:
ª$
©
This command reports that the data in ‘/usr/doc/HOWTO/README.gz’, a compressed file, is
English text.
NOTE: Currently, file differentiates among more than 100 different data formats, including several
human languages, many sound and graphics formats, and executable files for many different operating
systems.
¯ To change the timestamp of file ‘pizzicato’ to ‘17 May 1999 14:16’, type:
$ touch -d ’17 May 1999 14:16’ pizzicato RET
¯ To change the timestamp of file ‘pizzicato’ to ‘14 May’, type:
$ touch -d ’14 May’ pizzicato RET
¯ To change the timestamp of file ‘pizzicato’ to ‘14:16’, type:
$ touch -d ’14:16’ pizzicato RET
NOTE: When only the date is given, the time is set to ‘0:00’; when no year is given, the current year is
used.
See Info file ‘fileutils.info’, node ‘Date input formats’, for more information on date
input formats.
The difference report is output to standard output; to save it to a file, redirect the output to the file to
save to:
$ diff manuscript.old manuscript.new > manuscript.diff RET
In the preceding example, the difference report is saved to a file called ‘manuscript.diff’.
The difference report is meant to be used with commands such as patch, in order to apply the
differences to a file. See Info file ‘diff.info’, node ‘Top’, for more information on diff and the
format of its output.
To better see the difference between two files, use sdiff instead of diff; instead of giving a
difference report, it outputs the files in two columns, side by side, separated by spaces. Lines that differ
in the files are separated by ‘|’; lines that appear only in the first file end with a ‘<’, and lines that appear
only in the second file are preceded with a ‘>’.
¯ To peruse the files ‘laurel’ and ‘hardy’ side by side on the screen, with any differences indicated
between columns, type:
$ sdiff laurel hardy | less RET
NOTE: If there are files or subdirectories in the current directory with the same name as any of those in
the archive, those files will be overwritten when the archive is extracted. If you don’t know what files
are included in an archive, consider listing the contents of the archive first (see Section 8.6.2 [Listing the
Contents of an Archive], page 93).
Another reason to list the contents of an archive before extracting them is to determine whether the
files in the archive are contained in a directory. If not, and the current directory contains many unrelated
files, you might confuse them with the files extracted from the archive.
To extract the files into a directory of their own, make a new directory, move the archive to that
directory, and change to that directory, where you can then extract the files from the archive.
$ ci novel RET
novel,v <-- novel
enter description, terminated with single ’.’ or end of file:
NOTE: This is NOT the log message!
>> The Great American Novel. RET
>> . RET
ª
$
©
This command deposits the file in an RCS repository file called ‘novel,v’, and the original file,
‘novel’, is removed. To edit or access the file again, you must check out a revision of the file from RCS
with which to work (see Section 8.7.2 [Checking Out a File Revision], page 95).
Whenever you have a new revision that you want to save, use ci as before to check in the file. This
begins the process all over again.
For example, suppose you have checked out the first revision of ‘novel’ and changed the file so that
it now looks like this:
This is a very long tale about a great many things, including my long
voyage across America, and back home again.
¯
« ¨
To deposit this revision in RCS, type:
$ ci novel RET
novel,v <-- novel
new revision: 1.2; previous revision: 1.1
enter log message, terminated with single ’.’ or end of file:
>> Second draft. RET
>> . RET
ª$
©
If you create a subdirectory called ‘RCS’ (in all uppercase letters) in the current directory, RCS
recognizes this specially named directory instead of the current directory as the place to store the ‘,v’
revision files. This helps reduce clutter in the directory you are working in.
If the file you are depositing is a text file, you can have RCS insert a line of text, every time the
file is checked out, containing the name of the file, the revision number, the date and time in the UTC
(Coordinated Universal Time) time zone, and the user ID of the author. To do this, put the text ‘$Id$’
at a place in the file where you want this text to be written. You only need to do this once; each time you
check the file out, RCS replaces this string in the file with the header text.
For example, this chapter was written to a file, ‘managing-files.texinfo’, whose revisions
were tracked with RCS; the ‘$Id$’ string in this file currently reads:
$Id: managing-files.texinfo,v 1.32 2001/05/16 16:57:58 m Exp m $
This command checks out the latest revision of the file ‘novel’ from the RCS repository ‘novel,v’
(either from the current directory or in a subdirectory named ‘RCS’).
To check out a version other than the most recent version, specify the version number to check out
with the ‘-r’ option. Again, use the ‘-l’ option to allow the revision to be edited.
¯ To check out revision 1.14 of file ‘novel’, type:
$ co -l -r1.14 novel RET
NOTE: Before checking out an old revision of a file, remember to check in the latest changes first, or
they may be lost.
ª$
©
This command outputs the revision log for the file ‘novel’; it lists information about the RCS
repository, including its name (‘novel,v’) and the name of the actual file (‘novel’). It also shows that
there are two revisions—the first, which was checked in to RCS on 20 June 1991, and the second, which
was checked in to RCS the next day, on 21 June 1991.
PART THREE: Text
The Linux Cookbook: Tips and Techniques for Everyday Use
9 Viewing Text
Dealing with textual matter is the meat of Linux (and of most computing), so there are going to be many
chapters about the various aspects of text. This first chapter in this part of the book shows how to view
text on your display screen.
There are many ways to view or otherwise output text. When your intention is to edit the text of a
file, open it in a text editor, as described in Chapter 10 [Text Editing], page 107.
Some kinds of files—such as PostScript, DVI, and PDF files—often contain text in them, but they
are technically not text files. These are image format files, and I describe methods for viewing them in
Section 17.1 [Previewing Print Files], page 183.
NOTE: To learn how to browse files and their contents in a Web browser, see Section 5.9 [Browsing
Files], page 73.
This command starts less, opens in it all of the files that match the given pattern
«
‘/usr/doc/FAQ/unix-faq-part*’, and begins displaying the first one:
¨
ª ©
NOTE: When you specify more than one file to page, less displays each file in turn, beginning with
the first file you specify or the first file that matches the given pattern. To move to the next file, pressN;
to move to the previous file, press P.
The following table gives a summary of the keyboard commands that you can use while paging through
text in less. It lists the keystrokes and describes the commands.
K EYSTROKE C OMMAND
Scroll back through the text (“up”) one line.
Scroll forward through the text (“down”) one line.
or Scroll horizontally (left or right) one tab stop; useful for perusing files
that contain long lines.
PgUp or SPC Scroll forward through the text by one screenful.
PgDn Scroll backward through the text by one screenful.
C-l Redraw the screen.
/pattern Search forward through the file for lines containing pattern.
?pattern Search backward through the file for lines containing pattern.
< Move to beginning of the file.
> Move to end of the file.
h Display a help screen.
q Quit viewing the file and exit less.
9.2 Outputting Text
The simplest way to view text is to output it to standard output. This is useful for quickly looking at part
of a text, or for passing part of a text to other tools in a command line.
Many people still use cat to view a text file, especially if it is a very small file. To output all of a
file’s contents on the screen, use cat and give the file name as an argument.
This isn’t always the best way to peruse or read text—a very large text will scroll off the top of the
screen, for example—but sometimes the simple outputting of text is quite appropriate, such as when you
just want to output one line of a file, or when you want to output several files into one new file.
This section describes the tools used for such purposes. These tools are best used as filters, often at
the end of a pipeline, outputting the standard input from other commands.
NOTE: Tools and methods for outputting text for printing, such as outputting text in a font, are described
in Section 15.2 [Converting Plain Text for Output], page 159.
It is sometimes useful to view the end of a file on a continuing basis; this can be useful for a “growing”
file, a file that is being written to by another process. To keep viewing the end of such a file, use tail
with the ‘-f’ (“follow”) option. Type C-c to stop viewing the file.
¯ To follow the end of the file ‘access_log’, type:
$ tail -f access_log RET
NOTE: You can achieve the same result with less; to do this, type F while perusing the text (see
Section 9.1 [Perusing Text], page 99).
To output a region of more than one line, give the starting and ending line numbers, separated by a
comma.
¯ To output lines 47 to 108 of file ‘placement-list’, type:
$ sed ’47,108!d’ placement-list RET
You can also combine multiple head or tail commands on a pipeline to get the desired result (see
Section 3.2.4 [Redirecting Output to Another Command’s Input], page 37).
¯ To output the tenth line in the file ‘placement-list’, type:
$ head placement-list | tail -1 RET
¯ To output the fifth and fourth lines from the bottom of file ‘placement-list’, type:
$ tail -5 placement-list | head -2 RET
¯ To output the 500th character in ‘placement-list’, type:
$ head -c500 placement-list | tail -c1 RET
¯ To output the first character on the fifth line of the file ‘placement-list’, type:
$ head -5 placement-list | tail -1 | head -c1 RET
In the preceding example, three commands were used: the first five lines of the file
‘placement-list’ are passed to tail, which outputs the last line in the output (the fifth line in the
file); then, the last head command outputs the first character in that last line, which achieves the desired
result.
9.2.5 Outputting the Text between Strings
Use sed to select lines of text between strings and output either just that section of text, or all of the
lines of text except that section. The strings can be words or even regular expressions (see Section 14.2
[Regular Expressions—Matching Text Patterns], page 148).
Use the ‘-n’ option followed by ‘’/first /,/last /p’’ to output just the text between the strings first
and last, inclusive. This is useful for outputting, say, just one chapter or section of a text file when you
know the text used to begin the sections with.
¯ To output all the text from file ‘book-draft’ between ‘Chapter 3’ and ‘Chapter 4’, type:
$ sed -n ’/Chapter 3/,/Chapter 4/p’ book-draft RET
To output all of the lines of text except those between two patterns, omit the ‘-n’ option.
¯ To output all the text from file ‘book-draft’, except that which lies between the text ‘Chapter
3’ and ‘Chapter 4’, type:
$ sed ’/Chapter 3/,/Chapter 4/p’ book-draft RET
NOTE: For a more thorough introduction to sed, see Section 10.5 [Editing Streams of Text], page 116.
There are all kinds of tools that work as filters on text; this recipe describes a specific group of filters—
those that filter their standard input to give the text an accent or dialect, and are intended to be humorous.
Generally speaking, a filter is a tool that works on standard input, changing it in some way, and then
passing it to standard output.
¯ To apply the kraut filter to the text in the file ‘/etc/motd’, type:
$ cat /etc/motd | kraut RET
These commands pass the contents of the file ‘/etc/motd’ to the kraut filter, whose output is
then sent to standard output. The contents of ‘/etc/motd’ are not changed.
Some of the dialect filters available include nyc, which gives a “New Yawker” dialect to text, and
newspeak, which translates text into the approved language of the thought police, as described in
George Orwell’s novel, 1984. Hail Big Brother!
It’s been demonstrated that people read and comprehend printed text faster than they read and com-
prehend text displayed on a computer display screen. Rapid serial visual presentation, or RSVP, is
a technique that aims to increase reading speed and comprehension with the use of computer display
screens. With this technique, text is displayed streamed on the screen, one word at a time, with pauses
between words and punctuation. The average reading time is lowered and comprehension is increased
significantly with this technique.
GNOME sview is a “streaming viewer” for X; it streams text a word at a time on the screen, at a
default rate of 450 words per minute. Use it to read text files and the X selection, which is text you have
selected with the mouse (see Section 10.4 [Selecting Text], page 115).
To open a file in sview, either specify it as an argument to the command, or choose Open from the
File menu in sview, and select the file from there.
The Linux Cookbook: Tips and Techniques for Everyday Use
The large area with the word ‘beginning’ in it is where the text is being streamed. The text in the
lower-left window is a shrunken view of the entire file, the text in the lower-right window is the paragraph
from which the current word comes from.
To open another file, choose it from the menu; you can have many files open in sview at once.
sview places each file in its own buffer. You can also paste the X selection into a buffer of its own—to
switch to a different buffer, choose its name from the Buffer menu.
Type Q to quit reading and exit sview.
The following table lists the keyboard commands used in sview and describes their meaning.
K EYSTROKE D ESCRIPTION
Decrease the stream speed.
Increase the stream speed.
C-o Open a file.
C-q Quit viewing text and exit sview.
C-w Erase the current text buffer.
M-n Move forward to the next word.
M-p Move backward to the previous word.
S Toggle the streaming of text.
X Display the X selection in its own buffer.
N Move forward to the next paragraph.
P Move backward to the previous paragraph.
You can use the octal codes listed for each character to type them in Emacs—see Section 10.2.5
[Inserting Special Characters in Emacs], page 113.
The default Linux character set, the ISO 8859-1 (“Latin 1”) character set, contains all of the standard
ASCII character set plus an additional 128 characters.
To view the ISO 8859-1 character set, which contains an extended set of characters above the standard
127 ASCII characters, view the iso_8859_1 man page.
¯ To view the ISO 8859-1 character set, type:
$ man iso_8859_1 RET
You can use this page to see all of the characters in this character set and how to input them.
NOTE: There’s a special way to “quote” these characters in Emacs; this technique is described in Sec-
tion 10.2.5 [Inserting Special Characters in Emacs], page 113.
The ‘miscfiles’ package also contains charts for these character sets, as explained in Section 11.4
[Word Lists and Reference Files], page 130.
The Linux Cookbook: Tips and Techniques for Everyday Use
10 Text Editing
Text editing is one of the most fundamental activities of computing on Linux-based systems, or most any
computer for that matter. We edit text when writing a document, sending email, making a Web page,
posting an article for Usenet, programming—and the list goes on. Most people spend a good deal of their
computing time editing text with a text editor application.
There are a lot of text editors to choose from on Linux systems, as the first recipe in this chapter
shows, but the majority of editors fit in one of two families of editor: Emacs and Vi. Most users prefer
one or the other; rarely is one adept at both. I give more coverage to Emacs, and not only because it’s
my preferred editor—its keystroke commands are used by default in many other tools and applications,
including the bash shell (see Chapter 3 [The Shell], page 33).
nano Nano is a free software editor inspired by Pico, the editor that is included with
the University of Washington’s proprietary Pine email program. It’s also faster
than Pico, and comes with more features.
Debian: ‘nano’
WWW: http://www.nano-editor.org/
ted Ted is a WYSIWYG text editor for use in X which reads and writes ‘.rtf’ files
in Microsoft’s “Rich Text Format.”
Debian: ‘ted’
WWW: http://www.nllgg.nl/Ted/
the The Hessling Editor is a configurable editor that uses the Rexx macro language.
It was inspired by the XEDIT editor for VM/CMS and the Kedit editor for DOS.
Debian: ‘the’
Debian: ‘the-doc’
WWW: http://www.lightlink.com/hessling/THE/
vi Vi (pronounced “vye,” or sometimes “vee-eye”) is a visual, or full-screen, editor.
Touch typists often find its keystroke commands enable very fast editing.
Together with Emacs, Vi shares the spotlight for most popular editor on Linux
and Unix-based systems in general. Both were initially written in the same pe-
riod, and both have their staunch adherents. To run a hands-on tutorial, see Sec-
tion 10.3 [Running a Vi Tutorial], page 114.
Debian: ‘nvi’
WWW: ftp://mongoose.bostic.com/pub/nvi.tar.gz
vim Like the Elvis editor, Vim (“Vi improved”) is a modern implementation of Vi
whose new features include syntax coloring, scrollbars and menus, mouse sup-
port, and built-in help.
Debian: ‘vim’
WWW: http://www.vim.org/
wily Wily, an interesting mouse-centric editor, is inspired by the Acme editor from
AT&T’s Plan 9 experimental operating system. Wily commands consist of vari-
ous combinations of the three mouse buttons, called chords, which can be tricky
to master.
Debian: ‘wily’
WWW: http://www.cs.su.oz.au/˜gary/wily/
xedit Xedit is a simple text editor that comes with, and works in, X. It lets you insert,
delete, copy and paste text as well as open and save files—the very basics.
Debian: ‘xcontrib’
xemacs XEmacs is a version of Emacs with advanced capabilities for use in X, including
the ability to display images.
Debian: ‘emacsen-common’
Debian: ‘xemacs’
WWW: http://www.xemacs.org/
10.2 Emacs
Debian: ‘emacsen-common’
WWW: ‘http://www.emacs.org/’
To call Emacs a text editor does not do it justice—it’s a large application capable of performing many
functions, including reading email and Usenet news, browsing the World Wide Web, and even perfunc-
tory psychoanalysis.
There is more than one version of Emacs. GNU Emacs is the Emacs released under the auspices of
Richard Stallman, who wrote the original Emacs predecessor in the 1970s. XEmacs (formerly Lucid
Emacs) offers essentially the same features GNU Emacs does, but also contains its own features for use
with the X Window System (it also behaves differently from GNU Emacs in some minor ways).
GNU Emacs and XEmacs are by far the most popular emacsen (as they are referred to in number);
other flavors include jed (described in the previous section) and Chet’s Emacs, ce, developed by a
programmer at Case Western Reserve University.
Following is a brief introduction to using Emacs, interspersed with the necessary Emacs jargon;
following that are recipes that describe how to use some of Emacs’s advanced editing features.
The welcome message appears when Emacs first starts, and it tells you, among other things, how to
run a tutorial (which we’ll look at in just a minute).
The top bar is called the menu bar, and you can pull down its menus with the mouse (or, in the
console, with C-F10).
A file or other text open in Emacs is held in its own area called a buffer. By default, the current buffer
appears in the large area underneath the menu bar. To write text in the buffer, just type it. The place in
the buffer where the cursor is at is called point, and is referenced by many Emacs commands.
The horizontal bar near the bottom of the Emacs window and directly underneath the current buffer is
called the mode line ; it gives information about the current buffer, including its name, what percentage
of the buffer fits on the screen, what line point is on, and whether or not the buffer is saved to a file.
The mode line also lists the modes active in the buffer. Emacs modes are general states that control the
way Emacs behaves—for example, when Overwrite mode is set, text you type overwrites the text at
point; in Insert mode (the default), text you type is inserted at point. Usually, either Fundamental
mode (the default) or Text mode will be listed.
The Linux Cookbook: Tips and Techniques for Everyday Use
The echo area is where Emacs writes brief status messages, such as error messages; it is the last line
in the Emacs window. When you type a command that requires input, that input is requested in this area
(and when that happens, the place you type your input, in the echo area, is then called the minibuffer ).
Emacs commands usually begin with a Control or Meta (Escape) key sequence; many commands
begin with the C-x sequence, which you type by pressing and holding the CTRL key and then pressing
the X key (see [Typographical Conventions], page 3).
Because Emacs is different in culture from the editors and approach of the Microsoft Windows and
Apple MacOS world, it has gotten a rather unfounded reputation in those corners that it is odd and
difficult to use. This is not so. The keyboard commands to run its various functions are designed for ease
of use and easy recall.
For example, the find-file function prompts for the name of a file and opens a copy of the file in
a new buffer; its keyboard accelerator is C-x C-f (you can keep CTRL depressed while you press and
release the X and F keys).
You can run any Emacs function by typing M-x followed by the function name and pressing RET.
¯ To run the find-file function, type:
M-x find-file RET
This command runs the find-file function, which prompts for the name of a file and opens a
copy of the file in a new buffer.
Type C-g in Emacs to quit a function or command; if you make a mistake when typing a command,
this is useful to cancel and abort the keyboard input.
Now that we have run through the essential Emacs terminology, I’ll show you how to exit the
program—just type C-x C-c.
Emacs can have more than one buffer open at once. To switch between buffers, type C-x C-b. Then,
give the name of the buffer to switch to, followed by RET; alternatively, type RET without a buffer name
to switch to the last buffer you had visited. (Viewing a buffer in Emacs is called visiting the buffer.)
¯ To switch to a buffer called ‘rolo’, type:
C-x C-b rolo RET
A special buffer called ‘*scratch*’ is for notes and things you don’t want to save; it always exists
in Emacs.
¯ To switch to the ‘*scratch*’ buffer, type:
C-x C-b *scratch* RET
Any file names you give as an argument to emacs will open in separate buffers:
$ emacs todo rolo /usr/local/src/nirvarna/README RET
(You can also make new buffers and open files in buffers later, of course.)
Emacs comes with an interactive, self-paced tutorial that teaches you how to use the basics. In my
experience, setting aside 25 minutes to go through the tutorial is one of the best things you can do in
your computing career—even if you decide that you don’t like Emacs very much, a great many other
applications use Emacs-like keyboard commands and heuristics, so familiarizing yourself with them will
always pay off.
To start the tutorial at any time when you are in Emacs, type C-h t.
Incidentally, C-h is the Emacs help key; all help-related commands begin with this key. For example,
to read the Emacs FAQ, type C-h F, and to run the Info documentation browser (which contains The
GNU Emacs Manual ), type C-h i.
10.2.2 Basic Emacs Editing Keys
The following table lists basic editing keys and describes their function. Where two common keystrokes
are available for a function, both are given.
K EYS D ESCRIPTION
or C-p Move point up to the previous line.
or C-n Move point down to the next line.
or C-b Move point back through the buffer one character to the left.
or C-f Move point forward through the buffer one character to the right.
PgUp or C-v Move point forward through the buffer one screenful.
PgDn or M-v Move point backward through the buffer one screenful.
BKSP or C-h Delete character to the left of point.
DEL or C-d Delete character to the right of point.
INS Toggles between Insert mode and Overwrite mode.
Shift-INS or C-y Yank text in the kill ring at point (see Section 10.4.2 [Pasting Text],
page 115).
C-SPC Set mark (see Section 10.4.1 [Cutting Text], page 115).
C-_ Undo the last action (control-underscore).
C-a Move point to the beginning of the current line.
C-e Move point to the end of the current line.
C-g Cancel the current command.
C-h F Open a copy of the Emacs FAQ in a new buffer.
C-h a function RET List all Emacs commands related to function.
C-h i Start Info.
C-h k key Describe key.
C-h t Start the Emacs tutorial.
C-k Kill text from point to end of line.
C-l Re-center the text in the Emacs window, placing the line where point
is in the middle of the screen.
C-t Transpose the character at point with the character to the left of point.
C-u number Repeat the next command or keystroke you type number times.
C-w Kill text from mark to point.
C-x C-c Save all buffers open in Emacs, and then exit the program.
C-x C-f file RET Open file in a new buffer for editing. To create a new file that does
not yet exist, just specify the file name you want to give it. To browse
through your files, type TAB instead of a file name.
C-left-click Display a menu of all open buffers, sorted by major mode (works in X
only).
SHIFT-left-click Display a font selection menu (works in X only).
The Linux Cookbook: Tips and Techniques for Everyday Use
˜ < <<
˜ > >>
˜ ! ¡
˜ ? ¿
ˆ a â
ˆ e ê
ˆ i î
ˆ o ô
ˆ u û
/ a å
/ e æ
/ o ø
When a buffer contains accented characters, it can no longer be saved as plain ASCII text, but must
instead be saved as text in the ISO-8859-1 character set (see Section 9.4 [Viewing a Character Chart],
page 104). When you save a buffer, Emacs will notify you that it must do this.
¯ To type the line ‘Emacs ist spaß!’ in the current buffer, type:
M-x iso-accents-mode RET
Emacs ist spa"ss!
In the event that you want to type the literal key combinations that make up an accented character in
a buffer where you have ISO Accents mode on, type the prefix character twice.
¯ To type the text ‘’o’ (and not the accent character ó) in a buffer while ISO Accents mode is on,
type:
’’o
NOTE: GNU Emacs has recently added a number of internationalization functions. A complete dis-
cussion of their use is out of the scope of this book; for more information on this topic, see section
“International Character Set Support” in The GNU Emacs Manual .
The Vi editor comes with a hands-on, self-paced tutorial, which you can use in vi to learn how to use it.
It’s stored as a compressed file in the ‘/usr/doc/nvi’ directory; copy this file to your home directory,
uncompress it, and open it with vi to start the tutorial.
¯
« ¨
To run the vi tutorial, type the following from your home directory:
$ cp /usr/doc/nvi/vi.beginner.gz . RET
$ gunzip vi.beginner RET
ª$ vi vi.beginner RET
©
NOTE: An advanced tutorial is also available in ‘/usr/doc/nvi’.
10.4 Selecting Text
In X, you can cut and paste text between other windows, including xterm and Emacs windows. The
most recently selected text is called the X selection.
In the console, you can cut and paste text in the same virtual console or into a different virtual console.
To do this, you need the gpm package installed and set up for your mouse (it’s a default, recommended
package).
The operations described in this section work the same both in X and in virtual consoles. You cannot
presently cut and paste text between X and a virtual console.
Three buttons on the mouse are used for cutting and pasting. If you have a two-button mouse, your
administrator can set it to emulate three buttons—to specify the middle button, press the left and right
buttons simultaneously.
Click the left mouse button and drag the mouse over text to select it. You can also double-click the
left mouse button on a word to select that word, and triple-click the left mouse button on a line to select
that line. Furthermore, you can click the left mouse button at one end of a portion of text you want to
select, and then click the right mouse button at the other end to select all of the text between the points.
NOTE: In an xterm window, when you’re running a tool or application locally in a shell (such as the
lynx Web browser), the left mouse button alone won’t work. When this happens, press and hold the
SHIFT key while using the mouse to select text.
¯ You can also click the left mouse button at one end of an area of text and then double-click the right
mouse button at the other end of the area to kill the area of text.
¯ Finally, to kill a large portion of text in an Emacs buffer, set the mark at one end of the text by
moving point to that end and typing C-SPC. Then, move point to the other end of the text, and type
C-w to kill it.
To paste the text that was last selected with the mouse, click the middle mouse button at the place you
want to paste to. You can also use the keyboard by moving the cursor to where you want to paste and
then typing Shift-INS. These commands work both in X and in the console.
In X, to display the contents of the X selection in its own window, run the xpaste X client; its only
purpose in life is to display this text in its window.
In Emacs, pasting text is called yanking the text. Emacs offers the additional key, C-y (“yank”), to
yank the text that was last selected or killed. This key also works in the bash shell, where it pastes the
last text that was killed with C-k in that shell session, if any.
The Linux Cookbook: Tips and Techniques for Everyday Use
ª
$
©
In this example, the text file ‘novels’ was created and contains four lines of text (the last line with
the C-d is never part of the file).
Typing text like this without an editor will sometimes do in a pinch but, if you make a mistake, there
is not much recourse besides starting over—you can type C-u to erase the current line, and C-c to abort
the whole thing and not write the text to a file at all, but that’s about it.
Inserting text at the beginning of a text file without calling up a text editor is a bit trickier than appending
text to a file’s end—but it is possible.
To insert one or more lines of text at the beginning of a file, use ins. Give the name of the file in
which to insert text as an argument; ins will read lines of text from the standard input and insert them
at the beginning of the file. (It works by opening the file in ed, a simple line editor.)
Give the EOF—that is, type C-d on a line by itself—to signify the end of the lines of text to insert.
¯
« ¨
To insert several lines of text at the beginning of the file ‘novels’, type:
ª$
©
This command inserts two lines of text at the beginning of novels, the file used in the previous
examples in this section. This file would now contain the following:
The Novels of F. Scott Fitzgerald
---------------------------------
This Side of Paradise
The Beautiful and Damned
The Great Gatsby
Tender is the Night
The Last Tycoon
File inclusion is where the contents of a file can be included at a particular place within some other file,
just by specifying the file’s name at that place in the other file.
This is useful if you want or need to frequently rearrange divisions or sections of a document, if you
need to keep a document in more than one arrangement, or if you have some sections of text that you
frequently insert in more than one document. For these situations, you can keep each section in a separate
file and build an include file that contains the file names for the various sections in the order you want to
generate that file.
To include a file in a text file, specify the file to be included on a line of its own, like this:
include(file )
When you process this file for inclusion, the line with the ‘include’ statement is replaced with the
contents of the file file (whose path is relative to the current directory of the include file).
Use the m4 tool, the GNU macro processor, to process an include file. It takes as an argument the
name of the include file, and it outputs the inclusion to the standard output. You can use redirection to
redirect the output to a file.
For example, suppose the file ‘soups’ contains this text:
« ¨
Clam Chowder
Lobster Bisque
ª Vegetable
©
« ¨
And suppose the file ‘sandwiches’ contains this text:
BLT
Ham on Rye
ª Roast Beef
©
« ¨
And finally, suppose the file ‘menu’ contains this text:
Soups
-----
include(soups)
Sandwiches
----------
ªinclude(sandwiches) ©
¯ To process the file and write to the file ‘monday.txt’, type:
$ m4 menu > monday.txt RET
«
This command writes a new file, ‘monday.txt’, which looks like this:
¨
Diner Menu For Today
Soups
-----
Clam Chowder
Lobster Bisque
Vegetable
Sandwiches
----------
BLT
Ham on Rye
Roast Beef
ª ©
The Linux Cookbook: Tips and Techniques for Everyday Use
NOTE: You can write more than one include file that will use your files—and the files themselves can
have include files of their own.
This is a fairly simple use of m4; it can do much more, including run commands, manipulate text, and
run custom macros. See Info file ‘m4.info’, node ‘Top’ for more information on this tool.
11 Grammar and Reference
The tools and resources for writing and editing on Linux-based systems include spell checkers, dictio-
naries, and reference files. This chapter shows methods for using them.
11.1 Spelling
There are several ways to spell check text and files on Linux; the following recipes show how to find
the correct spellings of particular words and how to perform batch, interactive, and Emacs-based spell
checks.
The system dictionary file, ‘/usr/dict/words’, is nothing more than a word list (albeit a very
large one), sorted in alphabetical order and containing one word per line. Words that are correct regard-
less of case are listed in lowercase letters, and words that rely on some form of capitalization in order to
be correct (such as proper nouns) appear in that form. All of the Linux spelling tools use this text file to
check spelling; if a word does not appear in the dictionary file, it is considered to be misspelled.
NOTE: None of the computerized spell-check tools will correct your writing if you are using the wrong
word to begin with—for example, if you have ‘there’ when you mean ‘their’, the computer will not
catch it (yet!).
ª$
©
In the example, spell echoed the word ‘occurance’, meaning that this word was not in the
system dictionary and therefore was quite likely a misspelling. Then, C-d was typed to exit spell.
ª$
©
On an increasing number of systems, this file is being replaced with ‘/usr/share/dict/words’; administrators should
make a symbolic link from this to the shorter, preferred form.
The Linux Cookbook: Tips and Techniques for Everyday Use
In this example, three words are output: ‘occurance’, ‘willl’ and ‘occurance’ again, meaning
that these three words were found in ‘fall-lecture.draft’, in that order, and were not in the
system dictionary (and so were probably misspelled). Note that the misspelling ‘occurance’ appears
twice in the file.
To correct the misspellings, you could then open the file in your preferred text editor and edit it. Later
in this section I’ll describe an interactive spell checker that allows you to correct misspellings as they are
found. Still another option is to use a text editor with spell-checking facilities built in, such as Emacs.
¯ To spell check the file ‘fall-lecture.draft’, and output any possibly misspelled words to a
file ‘fall-lecture.spelling’, type:
$ spell fall-lecture.draft > fall-lecture.spelling RET
In this example, the standard output redirection character, ‘>’, is used to redirect the output to a file
(see Section 3.2.2 [Redirecting Output to a File], page 37).
To output an alphabetical list of the misspelled words, pipe the output to sort; then pipe the sorted
output to the uniq filter to remove duplicates from the list (uniq removes duplicate adjacent lines from
its input, outputting the “unique” lines).
¯ To output a sorted list of the misspelled words that are in the file ‘fall-lecture.draft’, type:
$ spell fall-lecture.draft | sort | uniq RET
ª ©
On the top line of the screen, ispell displays the misspelled word, followed by the name of the file.
Underneath this is the sentence in which the misspelling appears, with the word in question highlighted.
Following this is a list of suggested words, each offset by a number—in this example, ispell has only
one suggestion: ‘lectures’.
To replace a misspelling with a suggested word, type the number that corresponds to the suggested
word (in this example, you would type 0 to replace the misspelling with ‘lectures’). You only need
to type the number of your selection—a RET is not required.
You can also type a correction yourself; this is useful when ispell either offers no suggestions, or
when it does and the word you want is not one of them. To do this, type r (for “replace”) and then type
the replacement word, followed by RET.
Sometimes, ispell will question a word that you may not want to count as a misspelling, such as
proper names and the like—words that don’t appear in the system dictionary. There are a few things you
can do in such cases, as follows.
To accept a misspelled word as correct for the current ispell session only, type a; from then on
during the current session, this word will be considered correct.
If, however, you want ispell (and spell, and all other tools that access the system dictionary) to
remember this word as being correct for this and all future sessions, insert the word in your own personal
dictionary. Type u to insert a copy of the word uncapitalized, in all lowercase letters—this way, even if
the word is capitalized at the beginning of a sentence, the lowercase version of the word is saved. From
then on, in the current ispell session and in future sessions, this word, regardless of case, will be
considered correct.
When case is important to the spelling—for example, in a word that is a proper name such as
‘Seattle’, or a word with mixed case, such as ‘LaTeX’—type i to insert a copy of the word in
your personal dictionary with its case just as it appears; this way, words spelled with the same letters but
with different case will be considered misspellings.
When ispell finishes spell checking a file, it saves its changes to the file and then exits. It
also makes a copy of the original file, without the changes applied; this file has the same name
as the original but with ‘.bak’ added to the end—so in our example, the backup file is called
‘fall-lecture.notes.bak’. This is useful if you regret the changes you’ve made and want to
restore the file to how it was before you mucked it up—just remove the spell-checked file and then
rename the ‘.bak’ file to its original name.
The Linux Cookbook: Tips and Techniques for Everyday Use
11.2 Dictionaries
Debian: ‘wordnet-dev’
WWW: http://www.cogsci.princeton.edu/˜wn/
The term dictionary on Linux systems generally refers to one of two things: the traditional Unix-style
dictionary, which is an alphabetically sorted word list containing no actual definitions, and the newer
database-style dictionary that contains the headwords as well as their definitions. The latter is the kind of
thing most people mean when they talk about dictionaries. (When most Unix folk talk about dictionaries,
however, they almost always mean the former.)
WordNet is a lexical reference system in the form of a database containing thousands of words ar-
ranged in synonym sets. You can search the database and output the results in text with the wn tool or
the wnb X client (the “WordNet browser”).
Use of the X client is fairly straightforward—type a word in the dialog box near the top of the screen,
followed by RET, to get its definition(s), which are displayed in the large output window underneath the
dialog box.
For example, this is what appears when you do a search for the definition of the word ‘browse’:
Between the dialog box and the output window, there are menus for searching for synonyms and
other word senses. A separate menu is given for each part of speech a word may have; in the preceding
example, the word ‘browse’ can be either a noun or a verb, so two menus are shown.
To get a list of all word sense information available for a given word, run wn with the name of the
word as an argument. This outputs a list of all word sense information available for the word, with each
possible sense preceded with the name of the option to use to output it.
¯ To output a list of word senses available for the word ‘browse’, type:
$ wn browse RET
The DICT Development Group has a number of free dictionaries on their Web site at
http://www.dict.org/. On that page, you can look up the definitions of words (including
thesaurus and other searches) from a dictionary that contains over 300,000 headwords, or make a copy
of their dictionary for use on your own system. A dict client exists for accessing DICT servers and
outputting definitions locally; this tool is available in the ‘dict’ package.
DICT also has a number of specialized dictionaries that are plain text files (including the author’s Free
Journalism Dictionary, containing jargon and terms used in the journalism and publishing professions).
Their FILE project, The Free Internet Lexicon and Encyclopedia, is an effort to build a free, open source
collection of modern-word, idiom, and jargon dictionaries. FILE is a volunteer effort and depends on the
support of scholars and lexicographers; the DICT pages contain information on how to help contribute
to this worthy project.
Two venerable Unix tools for checking writing have recently been made available for Linux-based sys-
tems: style and diction.
Old-timers probably remember these names—the originals came with AT&T UNIX as part of the
much-loved “Writer’s Workbench” (WWB) suite of tools back in the late 1970s and early 1980s.
There was also a set of tools for formatting text called the “Documenter’s Workbench” (DWB), and there was a planned
“Reader’s Workbench”; we can only guess at what that might have been, but today we do have Project Gutenbook
(http://www.gutenbook.org/), a new etext reader.
The Linux Cookbook: Tips and Techniques for Everyday Use
AT&T “unbundled” the Writer’s Workbench from their UNIX version 7 product, and as the many
flavors of Unix blossomed over the years, these tools were lost by the wayside—eventually becoming
the stuff of Unix lore.
In 1997, Michael Haardt wrote new Linux versions of these tools from scratch. They support both
the English and German languages, and they’re now part of the GNU Project.
Two additional commands that were part of the Writer’s Workbench have long been standard on
Linux: look and spell, described previously in this chapter.
« ¨
a line by itself. This is especially useful when you want to check a single sentence:
$ diction RET
Let us ask the question we wish to state. RET
(stdin):1: Let us [ask the question -> ask]
[we wish to state -> (cliche, avoid)].
C-d
ª$
©
To check the text of a Web page, use the text-only Web browser lynx with the ‘-dump’ and
‘-nolist’ options to output the plain text of a given URL, and pipe this output to diction. (If
you expect there to be a lot of output, add another pipe at the end to less so you can peruse it.)
To peruse a copy of the text of http://example.org/1.html with markings for possible
wordy and misused phrases, type:
$ lynx -dump -nolist http://example.org/1.html | diction | less RET
The GNU Miscfiles are a collection of text files containing various facts and reference material, such as
common abbreviations, telephone area codes, and English connective phrases.
The files are stored in the ‘/usr/share/misc’ directory, and they are all compressed; use zless
to peruse them (see Section 9.1 [Perusing Text], page 99).
The following table lists the files in ‘/usr/share/misc’ and describes their contents.
F ILE D ESCRIPTION
GNU-manifesto.gz The GNU Manifesto.
abbrevs.talk.gz Collections of common abbreviations used in electronic communica-
abbrevs.gen.gz tion. (This is the place to look to find the secrets of ‘TTYL’ and ‘LOL’.)
airport.gz List of three-letter city codes for some of the major airports. The city
code is useful for querying the National Weather Service computers to
get the latest weather report for your region.
ascii.gz A chart of the ASCII character set.
birthtoken.gz The traditional stone and flower tokens for each month.
cities.dat.gz The population, political coordinates (nation, region), and geographic
coordinates (latitude, longitude) of many major cities.
inter.phone.gz International country and city telephone codes.
languages.gz Two-letter codes for languages, from ISO 639.
latin1.gz A chart of the extended ASCII character set, also known as the ISO
8859 (“Latin-1”) character set.
mailinglists.gz Description of all the public Project GNU-related mailing lists.
na.phone.gz North American (+1) telephone area codes.
operator.gz Precedence table for operators in the C language.
postal.codes.gz Postal codes for U.S. and Mexican states and Canadian provinces.
us-constitution.gz The Constitution of the United States of America (no Bill of
Rights, though). (On Debian systems, this file is placed in
‘/usr/share/state’.)
us-declaration.gz The Declaration of Independence of the Thirteen Colonies. (On De-
bian systems, this file is placed in ‘/usr/share/state’.)
rfc-index.txt Indexes of Internet standardization Request For Comments
(RFC) documents. (On Debian systems, this file is placed in
‘/usr/share/rfc’).
zipcodes.gz U.S. five-digit Zip codes.
‘miscfiles’ is not the only reference package available for Debian systems, though; other related
packages include the following:
PACKAGE D ESCRIPTION
doc-iana Internet protocol parameter registry documents, as published by the
Internet Assigned Numbers Authority.
doc-rfc A collection of important RFCs, stored in ‘/usr/share/rfc’.
jargon The “Jargon file,” which is the definitive dictionary of hacker slang.
vera List of computer acronyms.
The Linux Cookbook: Tips and Techniques for Everyday Use
NOTE: The official GNU miscfiles distribution also includes the Jargon file and the
‘/usr/dict/words’ dictionary file, which are available in separate packages for Debian, and
are removed from the Debian ‘miscfiles’ distribution. ‘/usr/dict/words’ is part of the
standard spelling packages, and the Jargon file comes in the optional ‘jargon’ package, and installs in
‘/usr/share/jargon’.
12 Analyzing Text
There are many ways to use command-line tools to analyze text in various ways, such as counting the
number of words in a text, creating a concordance, and comparing texts to see if (and where) they differ.
There are also other tricks you can do with text that count as analysis, such as finding anagrams and
palindromes, or cutting up text to generate unexpected combinations of words. This chapter covers all
these topics.
The following subsections describe how to specify just one kind of count with wc, and how to count
text in Emacs.
NOTE: You can get a count of how many different words are in a text, too—see Section 12.2 [Making a
Concordance of a Text], page 134. To count the average length of words, sentences, and paragraphs, use
style (see Section 11.3.3 [Checking Text for Readability], page 129).
To output counts for several files, first concatenate the files with cat, and then pipe the output to wc.
¯ To output the combined number of words for all the files with a ‘.txt’ file name extension in the
current directory, type:
$ cat *.txt | wc -w RET
NOTE: To read more about concatenation with cat, see Section 10.6 [Concatenating Text], page 116.
Use rel to analyze text files for relevance to a given set of keywords. It outputs the names of those files
that are relevant to the given keywords, ranked in order of relevance; if a file does not meet the criteria,
it is not output in the relevance listing.
rel takes as an option the keyword to search for in quotes; you can build a boolean expression by
grouping multiple keywords in parentheses and using any of the following operators between them:
O PERATOR D ESCRIPTION
| Logical “or.”
& Logical “and.”
! Logical “not.”
Give as arguments the names of the files to rank.
¯ To rank the files ‘report.a’, ‘report.b’, and ‘report.c’ in order of relevance to the key-
words ‘saving’ and ‘profit’, type:
$ rel "(saving & profit)" report.a report.b report.c RET
Give the name of a directory tree to analyze all files in the directory tree.
¯ To output a list of any files containing either ‘invitation’ or ‘request’ in the ‘˜/mail’
directory, ranked in order of relevancy, type:
$ rel "(invitation | request)" ˜/mail RET
¯ To output a list of any files containing ‘invitation’ and not ‘wedding’ in the ‘˜/mail’ di-
rectory, ranked in order of relevancy, type:
$ rel "(invitation ! wedding)" ˜/mail RET
¯ To output a list of any files containing ‘invitation’ and ‘party’ in the ‘˜/mail’ directory,
ranked in order of relevancy, type:
$ rel "(invitation & party)" ˜/mail RET
The purpose of the Remembrance Agent is to analyze the text you type in an Emacs session and, in the
background, find similar or relevant passages of text within your other files. It then outputs in a smaller
window a list of suggestions—those files that it has found—which you can open in a new buffer.
When installing the Remembrance Agent, you create three databases of the files to use when making
relevance suggestions; when remembrance-agent is running, it searches these three databases in
parallel, looking for relevant text. You could create, for example, one database of saved email, one of
your own writings, and one of saved documents.
¯To toggle the Remembrance Agent in the current buffer, type:
C-c r t
When remembrance-agent is running, suggested buffers will be displayed in the small
‘*Remembrance*’ buffer at the bottom of the screen. To open a suggestion in a new buffer, type C-c
r number , where number is the number of the suggestion.
¯
To open the second suggested file in a new buffer, type:
C-c r 2
The Linux Cookbook: Tips and Techniques for Everyday Use
An anagram is a word or phrase whose characters consist entirely of all the characters of a given word
or phrase—for example, ‘stop’ and ‘tops’ are both anagrams of ‘pots’.
Use an to find and output anagrams. Give as an argument the word or quoted phrase to use; an writes
its results to the standard output.
¯ To output all anagrams of the word ‘lake’, type:
$ an lake RET
¯ To output all anagrams of the phrase ‘lakes and oceans’, type:
$ an ’lakes and oceans’ RET
To limit the anagrams output to those containing a given string, specify that string with the ‘-c’
option.
¯ To output only anagrams of the phrase ‘lakes and oceans’ which contain the string ‘seas’,
type:
$ an -c seas ’lakes and oceans’ RET
To print all of the words that some or all letters in a given word or phrase can make, use the ‘-w’
option. This outputs words that are not anagrams, since anagrams must contain all of the letters of the
other word or phrase.
¯ To output all of the words that can be made from the letters of the word ‘seas’, type:
$ an -w seas RET
This command outputs all of the words that can be formed from all or some of the characters in
‘seas’, including ‘see’ and ‘as’.
To perform a simple cut-up of a text, use cutup. It takes the name of a file as input and cuts it both
horizontally and vertically along the middle, rearranges the four sections to their diagonally opposite
corners, and then writes that cut-up to the standard output. The original file is not modified.
¯ To make a cut-up from a file called ‘nova’, type:
$ cutup nova RET
No simple cut-up filter, Jamie Zawinski’s dadadodo uses the computer to go one step beyond—it
generates passages of random text whose structure and characters are similar to the text input you give
it. The program works better on larger texts, where more subtleties can be analyzed and hence more
realistic-looking text is output.
Give as an argument the name of the text file to be used; by default, dadadodo outputs text to
standard output until you interrupt it by typing C-c.
¯ To output random text based on the text in the file ‘nova’, type:
$ dadadodo nova RET
This command will output passages of random text based on the text in the file ‘nova’ until it is
interrupted by the user.
You can analyze a text and save the analysis to a file of compiled data; this analysis can then be used
to generate random text when the original input text is not present. The following table describes this
and other dadadodo options.
O PTION D ESCRIPTION
-c integer Generate integer sentences (default is 0, meaning “generate an infinite
amount until interrupted”).
-l file Load compiled data in file and use it to generate text.
-o file Output compiled data to file file for later use.
-p integer Pause for integer seconds between paragraphs.
¯ To generate a Dissociated Press cut-up from the current buffer, always overlapping by three charac-
ters, type:
C-u 3 M-x dissociated-press RET
¯ To generate a Dissociated Press cut-up from the current buffer, always overlapping by one word,
type:
C-u -1 M-x dissociated-press RET
13 Formatting Text
Methods and tools for changing the arrangement or presentation of text are often useful for preparing
text for printing. This chapter discusses ways of changing the spacing of text and setting up pages, of
underlining and sorting and reversing text, and of numbering lines of text.
¯ To output only the lines from the file ‘term-paper’ that contain more than just space characters,
type:
$ grep ’[ˆ ].’ term-paper RET
To output only the lines from the file ‘term-paper’ that contain more than just space or tab
characters, type:
$ grep ’[ˆ[:space:]].’ term-paper RET
If a file is already double-spaced, where all even lines are blank, you can remove those lines from the
output by using sed with the ‘n;d’ expression.
¯ To output only the odd lines from file ‘term-paper’, type:
$ sed ’n;d’ term-paper RET
To specify the number of spaces to convert to a tab, give that number as an argument to the ‘-t’
option.
¯ To convert every leading space character to a tab character in ‘list2’, and write the output to the
standard output, type:
$ unexpand -t 1 list2 RET
By default, pr outputs pages of 66 lines each. You can specify the page length as an argument to the
‘-l’ option.
¯ To paginate the file ‘listings’ with 43-line pages, and write the output to a file called
‘listings.page’, type:
$ pr -f -h "" -l 43 listings > listings.page RET
NOTE: If a page has more lines than a printer can fit on a physical sheet of paper, it will automatically
break the text at that line as well as at the places in the text where there are formfeed characters.
You can paginate text in Emacs by manually inserting formfeed characters where you want them—see
Section 10.2.5 [Inserting Special Characters in Emacs], page 113.
To output such text without the backspace character, C-h, in the output, use col with the ‘-u’ option.
¯ To output the file ‘term-paper’ with all backspace characters stripped out, type:
$ col -u term-paper RET
ª
$
©
¯ To sort the file ‘provinces’ and output all lines in descending order, type:
« ¨
$ sort -r provinces RET
Szechwan
Shantung
Kwangtung
Kiangsu
Hunan
Honan
Fukien
ª$
©
The following table describes some of sort’s options.
O PTION D ESCRIPTION
-b Ignore leading blanks on each line when sorting.
-d Sort in “phone directory” order, with only letters, digits, and blanks being sorted.
-f When sorting, fold lowercase letters into their uppercase equivalent, so that dif-
ferences in case are ignored.
-i Ignore all spaces and all non-typewriter characters when sorting.
-n Sort numerically instead of by character value.
-o file Write output to file instead of standard output.
¯ To peruse the text file ‘report’ with each line of the file numbered, type:
$ cat -n report | less RET
¯ To peruse the text file ‘report’ with each non-blank line of the file numbered, type:
$ cat -b report | less RET
In the preceding examples, output from cat is piped to less for perusal; the original file is not
altered.
To take an input file, number its lines, and then write the line-numbered version to a new file, send
the standard output of the cat command to the new file to write.
¯ To write a line-numbered version of file ‘report’ to file ‘report.lines’, type:
$ cat -n report > report.lines RET
¯ To output all lines in the file ‘book’ that begin with the text ‘in the beginning’, regardless of
case, type:
$ grep -i ’ˆin the beginning’ book RET
NOTE: These regexps were quoted with ’ characters; this is because some shells otherwise treat the
‘ˆ’ character as a special “metacharacter” (see Section 3.1.1 [Passing Special Characters to Commands],
page 34).
The ed command is still available on virtually all unices, Linux inclusive, and the old ‘g/re/p’ still works.
The default shell on most Linux systems, bash, doesn’t—but it’s still probably good practice to quote a regexp with a caret
in it.
The Linux Cookbook: Tips and Techniques for Everyday Use
NOTE: To use ‘$’ in a regexp to find words that rhyme with a given word, see Section 11.2.1 [Listing
Words that Match a Pattern], page 126.
For longer lines, it is more useful to use a different construct: ‘ˆ.\{number \}$’, where number is
the number of lines to match. Use ‘,’ to specify a range of numbers.
¯ To output all lines in ‘/usr/dict/words’ that are exactly seventeen characters wide, type:
$ grep ’ˆ.\{17\}$’ /usr/dict/words RET
¯ To output all lines in ‘/usr/dict/words’ that are twenty-five or more characters wide, type:
$ grep ’ˆ.\{25,\}$’ /usr/dict/words RET
This command outputs any lines in ‘playlist’ that match the patterns ‘the sea’ or ‘cake’,
including lines matching both patterns.
NOTE: To match lines containing some regexps in a particular order, see Section 14.2.11 [Regexps for
Common Situations], page 152.
14.2.6 Matching Lines That Don’t Contain a Regexp
To output all lines in a text that don’t contain a given pattern, use grep with the ‘-v’ option—this option
reverts the sense of matching, selecting all non-matching lines.
¯ To output all lines in ‘/usr/dict/words’ that are not three characters wide, type:
$ grep -v ’ˆ...$’ RET
¯ To output all lines in ‘access_log’ that do not contain the string ‘http’, type:
$ grep -v http access_log RET
You can also search and replace text in an Emacs buffer; to do this, use the replace-regexp
function and give both the expression to search for and the expression to replace it with.
¯ To replace the text ‘helpless’ with the text ‘helpful’ in the current buffer, type:
M-x replace-regexp RET helpless RET helpful RET
NOTE: You can also search and replace text in most text editors, including Emacs; see Section 14.6.4
[Searching and Replacing in Emacs], page 155.
Printed, typeset output and electronic Internet FAQ, white paper, enscript; Texinfo;
HTML or text file dissertation SGMLtools
Printed, typeset output and text file man page, command refer- groff
ence card
Printed, typeset output Letter or other corre- LaTeX or LyX
spondence, report, book
manuscript
Printed, typeset output Brochure or newsletter with LyX
multiple columns and im-
ages
Printed, typeset output Envelope, mailing label, TEX
other specialized document
Printed text output in a font Grocery list, saved email enscript
message, to-do list
Printed, typeset output Poster, sign enscript; HTML; LyX;
TEX
Large printed text output Long banners for parties or banner
other occasions
NOTE: If you really don’t need a document to be typeset, then don’t bother! Just keep it a plain text
file, and use a text editor to edit it (see Chapter 10 [Text Editing], page 107). Do this for writing notes,
email messages, Web pages, Usenet articles, and so forth. If you ever do need to typeset it later, you will
still be able to do so. And you can, if you like, view or print plain text in nice fonts (see Section 15.2.1
[Outputting Text in a Font], page 159).
15.2 Converting Plain Text for Output
Debian: ‘enscript’
WWW: http://www.iki.fi/˜mtr/genscript/
The simplest way to typeset plain text is to convert it to PostScript. This is often done to prepare text
for printing; the original source text file remains as unformatted text, but the text of the printed output is
formatted in basic ways, such as being set in a font.
The main tool for converting text to PostScript is called enscript; it converts the text file that is
specified as an argument into PostScript, making any number of formatting changes in between. It’s
great for quickly making nice output from a plain text file—you can use it to do things such as output
text in a font of your choosing, or paginate text with graphical headers at the top of each page.
By default, enscript paginates its input, outputs it in a 10-point Courier font, and puts a simple
header at the top of each page containing the file name, date and time, and page number in bold. Use the
‘-B’ option to omit this header.
If you have a PostScript printer connected to your system, enscript can be set up to spool its
output right to the printer. You can verify if your system is set up this way by looking at the enscript
configuration file, ‘/etc/enscript.cfg’. The line
DefaultOutputMethod: printer
specifies that output is spooled directly to the printer; changing it to ‘stdout’ instead of ‘printer’
sends the output to the standard output instead.
Even if your default printer does not natively understand PostScript, it may be able to take enscript
output, anyway. Most Linux installations these days have print filters set up so that PostScript spooled
for printing is automatically converted to a format the printer understands (if your system doesn’t have
this setup for some reason, convert the PostScript to a format recognized by your printer with the gs
tool, and then print that—see Section 20.3 [Converting PostScript], page 209).
¯ To convert the text file ‘saved-mail’ to PostScript, with default formatting, and spool the output
right to the printer, type:
$ enscript saved-mail RET
To write the output to a file instead of spooling it, give the name of the file you want to output as an
argument to the ‘-p’ option. This is useful when you don’t have a PostScript printer and you need to
convert the output first, or for when you just want to make a PostScript image file from some text, or for
previewing the output before you print it. In the latter case, you can view it on the display screen with
a PostScript viewer application such as ghostview (see Section 17.1.2 [Previewing a PostScript File],
page 183).
¯ To write the text file ‘saved-mail’ to a PostScript file, ‘saved-mail.ps’, and then preview it
in X, type:
$ enscript -p report.ps saved-mail RET
$ ghostview saved-mail.ps RET
The following recipes show how to use enscript to output text with different effects and properties.
NOTE: Once you make a PostScript file from text input, you can use any of the tools to format this new
PostScript file, including rearranging and resizing its pages (see Chapter 20 [PostScript], page 205).
‘Courier14’ outputs text in the Courier font at 14 points, and ‘Times-Roman12.2’ outputs text
in the Times Roman font at 12.2 points. Some of the available font names are listed in the file
‘/usr/share/enscript/afm/font.map’; the enscript man page describes how to use addi-
tional fonts that might be installed on your system.
¯ To print the contents of the text file ‘saved-mail’ on a PostScript printer, with text set in the
Helvetica font at 12 points, type:
$ enscript -B -f "Helvetica12" saved-mail RET
¯ To make a PostScript file called ‘saved-mail.ps’ containing the contents of the text file
‘saved-mail’, with text set in the Helvetica font at 12 points, type:
$ enscript -B -f "Helvetica12" -p saved-mail.ps saved-mail RET
The ‘-B’ option was used in the preceding examples to omit the output of a header on each page.
When headers are used, they’re normally output in 10-point Courier Bold; to specify a different font for
the text in the header, give its name as an argument to the ‘-F’ option.
¯ To print the contents of the text file ‘saved-mail’ to a PostScript printer, with text set in 10-point
Times Roman and header text set in 18-point Times Bold, type:
$ enscript -f "Times-Roman10" -F "Times-Bold18" saved-mail RET
¯ To make a PostScript file called ‘saved-mail.ps’ containing the contents of the text file
‘saved-mail’, with text and headers both set in 16-point Palatino Roman, type:
$ enscript -f "Palatino-Roman16" -F "Palatino-Roman16" -p
saved-mail.ps saved-mail RET
ªC-d
©
72-point type is very large; use the ‘--word-wrap’ option with longer lines of text to wrap lines
at word boundaries if necessary. You might need this option because at these larger font sizes, you run
the risk of making lines that are longer than could fit on the page. You can also use the ‘-r’ option
to print the text in landscape orientation, as described in Section 15.2.5 [Outputting Text in Landscape
Orientation], page 163.
¯
«
To print a sign in 63-point Helvetica Bold across the long side of the page, type:
¨
$ enscript -B -r --word-wrap -f "Helvetica-Bold63" RET
RET
RET
CAUTION -- WET PAINT! RET
ªC-d
©
NOTE: To make a snazzier or more detailed message or sign, you would create a file in a text editor and
justify the words on each line in the file as you want them to print, with blank lines where necessary.
If you’re getting that complicated with it, it would also be wise to use the ‘-p’ option once to output
to a file first, and preview the file before printing it (see Section 17.1.2 [Previewing a PostScript File],
page 183).
NOTE: You can create your own custom fancy headers, too—this is described in the
‘CUSTOMIZATION’ section of the enscript man page.
LyX is a relative newcomer to the typesetting and word-processing arena, and it is one of the most
genuinely fresh ideas in the field: it’s a kind of word processor for writing LaTeX input (see Section 15.4
[Typesetting with TEX and Friends], page 167). It’s a visual, graphic editor for X, but it doesn’t emulate
the output paper directly on the display screen. In contrast to specifying exactly how each character in
the document will look (“make this word Helvetica Bold at 18 points”), you specify the structure of the
text you write (“make this word a chapter heading”). And, in contrast to the WYSIWYG paradigm, its
authors call the new approach WYSIWYM—“What you say is what you mean.”
LyX comes with many document classes already defined—such as letter, article,
report, and book—containing definitions for the elements these document types may contain. You
can change the look of each element and the look of the document as a whole, and you can change the
look of individual selections of text, but with these elements available, it’s rarely necessary.
Since LyX uses LaTeX as a back-end to do the actual typesetting, and LyX is capable of exporting
documents to LaTeX input format, you can think of it as a way to write LaTeX input files in a GUI
without having to know the LaTeX language commands.
However, even those who do use LaTeX and related typesetting languages can get some use out of
LyX: many people find it quick and easy to create some documents in LyX that are much harder to do in
LaTeX, such as multi-column newsletter layouts with illustrations.
You can also import your LaTeX files (and plain text) into LyX for further layout or manipulation.
The following recipes show how to get started using LyX, and where to go to learn more about it.
To print the document, choose Print from the File menu. You can also export it to LaTeX,
PostScript, DVI, or plain text formats; to do this, choose Export from the File menu and then select
the format to export to.
NOTE: If you plan on editing the document again in LyX, be sure to save the actual ‘.lyx’ document
file.
The most capable typesetting tool for use on Linux-based systems is the TEX typesetting system and
related software. It is the premier computer typesetting system—its output surpasses or rivals all other
systems to date. The advanced line and paragraph breaking, hyphenation, kerning, and other font char-
acteristic policies and algorithms it can perform, and the level of precision at which it can do them, have
yet to be matched in word processors.
The TEX system itself—not a word processor or single program, but a large collection of files and
data—is packaged in distributions; teTEX is the TEX distribution designed for Linux.
TEX input documents are plain text files written in the TEX formatting language, which the TEX tools
can process and write to output files for printing or viewing. This approach has great benefits for the
writer: the plain text input files can be written with and exchanged between many different computer
systems regardless of operating system or editing software, and these input files do not become obsolete
or unusable with new versions of the TEX software.
Donald Knuth, the world’s foremost authority on algorithms, wrote TEX in 1984 as a way to type-
set his books (http://www-cs-faculty.stanford.edu/˜knuth/taocp.html), because
he wasn’t satisfied with the quality of available systems. Since its first release, many extensions to
the TEX formatting language have been made—the most notable being Leslie Lamport’s LaTeX, which
is a collection of sophisticated macros written in the TEX formatting language, designed to facilitate
the typesetting of structured documents. (LaTeX probably gets more day-to-day use than the plain TEX
format, but in my experience, both systems are useful for different kinds of documents.)
The collective family of TEX and related programs are sometimes called “TEX and friends,” and
abbreviated as ‘texmf’ in some TEX references : for example, the supplementary files included with
the bare TEX system are kept in the ‘/usr/lib/texmf’ directory tree.
The following recipes describe how to begin writing input for TEX and how to process these files for
viewing and printing. While not everyone wants or even has a need to write documents with TEX and
The ‘mf’ also stands for “Metafont,” the name of the font language that is part of T X.
E
The Linux Cookbook: Tips and Techniques for Everyday Use
LaTeX, these formats are widely used, especially on Linux systems, so every Linux user has the potential
to encounter one of these files, and ought to know how to process them.
NOTE: “TEX” doesn’t sound like the name of a cowboy, nor “LaTeX” like a kind of paint: the letters ‘T’,
‘E’, and ‘X’ represent the Greek characters tau, epsilon, and chi (from the Greek ‘techne’, meaning art
and science). So the last sound in “TEX” is like the ‘ch’ in ‘Bach’, and “LaTeX,” depending on local
dialect, is pronounced either ‘lay-teck’ or ‘lah-teck’. Those who become highly adept at using
the system, Knuth calls “TEXperts.”
To create a document with TEX or LaTeX, you generally use your favorite text editor to write an input
file containing the text in TEX or LaTeX formatting. Then, you process this TEX or LaTeX input file to
create an output file in the DVI format, which you can preview, convert, or print.
It’s an old tradition among programmers introducing a programming language to give a simple pro-
gram that just outputs the text ‘Hello, world’ to the screen; such a program is usually just detailed
enough to give those unfamiliar with the language a feel for its basic syntax.
We can do the same with document processing languages like TEX and LaTeX. Here’s the “Hello,
world” for a TEX document:
Hello, world
\end
If you processed this input file with tex, it would output a DVI file that displayed the text ‘Hello,
world’ in the default TEX font, on a default page size, and with default margins.
Here’s the same “Hello, world” for LaTeX:
\documentclass{article}
\begin{document}
Hello, world
\end{document}
Even though the TEX example is much simpler, LaTeX is generally easier to use for making struc-
tured documents. Plain TEX, on the other hand, is better for more experimental layouts or specialized
documents.
The TEX and LaTeX markup languages are worth a book each, and providing an introduction to
their use is well out of the scope of this text. To learn how to write input for them, I suggest two
excellent tutorials, Michael Doob’s A Gentle Introduction to TEX, and Tobias Oetiker’s The Not So
Short Introduction to LaTeX—each available on the WWW at the URLs listed above. These files are
each in the respective format they describe; in order to read them, you must process these files first, as
described in the two previous recipes.
Good LaTeX documentation in HTML format can be found installed on many Linux systems in the
‘/usr/share/texmf/doc/latex/latex2e-html/’ directory; use the lynx browser to view
it (see Section 5.9 [Browsing Files], page 73).
Some other typesetting systems, such as LyX, SGMLtools, and Texinfo (all described elsewhere in
this chapter), write TEX or LaTeX output, too—so you can use those systems to produce said output
without actually learning the TEX and LaTeX input formats. (This book was written in Emacs in Texinfo
format, and the typeset output was later generated by TEX.)
NOTE: The Oetiker text consists of several separate LaTeX files in the ‘lshort’ directory; download
and save all of these files.
The Linux Cookbook: Tips and Techniques for Everyday Use
A collection of sample templates for typesetting certain kinds of documents in TEX and LaTeX can be
found at the URL listed above. These templates include those for creating letters and correspondence,
articles and term papers, envelopes and mailing labels, and fax cover sheets. If you’re interested in
making typeset output with TEX and LaTeX, these templates are well worth exploring.
To write a document with a template, insert the contents of the template file into a new file that has a
‘.tex’ or ‘.ltx’ extension, and edit that. (Use your favorite text editor to do this.)
To make sure that you don’t accidentally overwrite the actual template files, you can write-protect
them (see Section 6.3.3 [Write-Protecting a File], page 78):
$ chmod a-w template-file-names RET
In the templates themselves, the bracketed, uppercase text explains what kind of text belongs there;
fill in these lines with your own text, and delete the lines you don’t need. Then, process your new file
with either latex or tex as appropriate, and you’ve got a typeset document!
The following table lists the file names of the TEX templates, and describes their use. Use tex to
process files you make with these templates (see Section 15.4.2 [Processing TEX Files], page 168).
T EMPLATE F ILE D ESCRIPTION
fax.tex A cover sheet for sending fax messages.
envelope.tex A No. 10 mailing envelope.
label.tex A single mailing label for printing on standard 15-up sheets.
The following table lists the file names of the LaTeX templates, and describes their use. Use latex
to process files you make with these templates (see Section 15.4.3 [Processing LaTeX Files], page 168).
T EMPLATE F ILE D ESCRIPTION
letter.ltx A letter or other correspondence.
article.ltx An article or a research or term paper.
manuscript.ltx A book manuscript.
There are more complex template packages available on the net that you might want to look at:
¯Rob Rutten has assembled a very nice collection of LaTeX templates,
http://www.astro.uu.nl/˜rutten/rrtex/templates/
¯The largest listing of LaTeX and TeX templates and style files is in the TEX Catalogue Online,
ftp://ftp.cdrom.com:21/pub/tex/ctan/help/Catalogue/hier.html
¯The Midnight Macros are a collection of TEX macros for printing booklets, bulk letters, and outlines,
ftp://ftp.cdrom.com/pub/tex/ctan/macros/generic/midnight/
¯Björn Magnusson’s LaTeX templates for folder and register labels,
http://www.ifm.liu.se/˜bjmag/latex.shtml
<sect>Introduction
<p>Hello, world.
</article>
A simple example document and the various output files it generates are on the SGMLtools site at
http://www.sgmltools.org/old-site/example/index.html.
The SGMLtools package also comes with a simple example file, ‘example.sgml.gz’, which is
installed in the ‘/usr/doc/sgml-tools’ directory.
The Linux Cookbook: Tips and Techniques for Everyday Use
ª$
©
In this example, sgml2latex writes a LaTeX input file from the SGML source file, and then the
latex tool processes the LaTeX file to make DVI output, which is processed with dvips to get the
final output: a PostScript file called ‘myfile.ps’ with a paper size of US letter.
To make a PDF file from the PostScript file, you need to take one more step and use ps2pdf, part of
the gs or Ghostscript package; this converts the PostScript to PDF.
¯ To make a PDF file from the PostScript file ‘myfile.ps’, type:
$ ps2pdf myfile.ps myfile.pdf RET
15.6 Other Word Processors and Typesetting Systems
The following table describes other popular word processors and typesetting tools available for Linux.
Those systems not in general use have been silently omitted.
S YSTEM D ESCRIPTION
AbiWord A graphical, WYSIWYG-style word processor for Linux systems. It
can read Microsoft Word files.
WWW: http://www.abisource.com/
groff GROFF is the latest in a line of phototypesetting systems that have
been available on Unix-based systems for years; the original in this
line was roff (“runoff,” meaning that it was for files to be run off
to the printer). groff is used in the typesetting of man pages, but
it’s possible to use it to create other kinds of documents, and it has a
following of staunch adherents.
To output the tutorial file included with the groff distribution to a
DVI file called ‘intro.dvi’, type:
$ zcat /usr/doc/groff/me-intro.me.gz | groff
-me -T dvi > intro.dvi RET
Debian: ‘groff’
Maxwell A graphical word processor for use in X.
WWW: http://www.eeyore-mule.demon.co.uk/
PostScript The PostScript language is generally considered to be a format gen-
erated by software, but some people write straight PostScript! Sec-
tion 15.2 [Converting Plain Text for Output], page 159, has recipes
on creating PostScript output from text, including outputting text in a
font.
People have written PostScript template files for creating all kinds of
documents—from desktop calendars to mandalas for meditation. The
Debian ‘cdlabelgen’ and ‘cd-circleprint’ packages contain
tools for writing labels for compact discs. Also of interest are Jamie
Zawinski’s templates for printing label inserts for video and audio
tapes; edit the files in a text editor and then view or print them as you
would any PostScript file.
WWW: http://www.jwz.org/audio-tape.ps
WWW: http://www.jwz.org/video-tape.ps
StarWriter A traditional word processor for Linux systems, part of the StarOffice
application suite. It can also read Microsoft Word files.
WWW: http://www.sun.com/staroffice/
Texinfo Texinfo is the GNU Project’s documentation system and is an excellent
system for writing FAQs or technical manuals. It allows for the inclu-
sion of in-line EPS images and can produce both TEX-based, HTML,
and Info output—use it if this matches your needs.
Debian: ‘tetex-base’
WWW: http://www.texinfo.org/
The Linux Cookbook: Tips and Techniques for Everyday Use
16 Fonts
A font is a collection of characters for displaying text, normally in a common typeface and with a
common size, boldness, and slant.
This chapter discusses the most popular kinds of fonts used on Linux systems: display fonts for use
in the X Window System, fonts for use in virtual consoles, and the “fonts” often seen in Usenet and email
composed entirely of ASCII characters.
Omitted are reference of the use of fonts with TEX, which are the kind of fonts you’re most likely
to use when producing typeset output—it is beyond the scope of this book to cover that issue with the
space it needs. However, to print a text file with a font, see Section 15.2.1 [Outputting Text in a Font],
page 159.
For more information on fonts and the tools to use them, see the Font HOWTO (see Section 2.8.6
[Reading System Documentation and Help Files], page 31).
16.1 X Fonts
You can specify a font as an option to most X clients, so that any text in the client is written in the given
font. The recipe that describes how to do this is in Section 4.2.3 [Specifying a Window Font], page 51.
When you specify a font as an option, you have to give the X font name, which is the exact name
used to specify a specific font in X. (An easy way to get the X font name is described in the first recipe
in this section.) X font names consist of 14 fields, delimited by (and beginning with) a hyphen. All fields
must be specified, and empty fields are permitted:
-fndry-fmly-wght-slant-swdth-adstyl-pxlsz
-ptsz-resx-resy-spc-avgwdth-rgstry-encdng
The preceding line was split because of its length, but X font names are always given on one line.
The following table describes the meaning of each field.
F IELD D ESCRIPTION
fndry The type foundry that digitized and supplied the font data.
fmly The name of the typographic style (for example, ‘courier’).
wght The weight of the font, or its nominal blackness, the degree of bold-
ness or thickness of its characters. Values include ‘heavy’, ‘bold’,
‘medium’, ‘light’, and ‘thin’.
slant The posture of the font, usually ‘r’ (for ‘roman’, or upright), ‘i’
(‘italic’, slanted upward to the right and differing in shape from the
roman counterpart), or ‘o’ (‘oblique’, slanted but with the shape of
the roman counterpart).
swdth The proportionate width of the characters in the font, or its nominal
width, such as ‘normal’, ‘condensed’, ‘extended’, ‘narrow’,
and ‘wide’.
adstyl Any additional style descriptions the particular font takes, such as
‘serif’ (fonts that have small strokes drawn on the ends of each line
in the character) or ‘sans serif’ (fonts that omit serifs).
pxlsz The height, in pixels, of the type. Also called body size.
ptsz The height, in points, of the type.
resx The horizontal screen resolution the font was designed for, in dpi
(“dots per inch”).
The Linux Cookbook: Tips and Techniques for Everyday Use
resy The vertical screen resolution the font was designed for, in dpi.
spc The kind of spacing used by the font (its escapement class ); either ‘p’
(a proportional font containing characters with varied spacing), ‘m’ (a
monospaced font containing characters with constant spacing), or ‘c’
(a character cell font containing characters with constant spacing and
constant height).
avgwdth The average width of the characters used in the font, in 1/10th pixel
units.
rgstry The international standards body, or registry, that owns the encoding.
encdng The registered name of this character set, or its encoding.
The row of buttons are pull-down menus containing options available on your system for each field
in the X font name. Use the mouse to select items from each menu, and the X font you have selected is
shown in the main window. Above it is written its X font name.
¯ To make the X font name the X selection, click the mouse on the button labeled select.
This example makes the X font name the X selection, which makes it possible to paste the X font
name to a command line or into another window (see Section 10.4.2 [Pasting Text], page 115).
Some font files contain more than one height (or size) of the font. If a font contains more than one
encoding for different heights, give the height to use as an argument to the ‘-H’ option. (If you try to do
it without the option anyway, consolechars will output a list of available sizes.)
Common console font heights include 8 (for 8x8 fonts), 14 (for 8x14 fonts), and 16 (for 8x16 fonts).
¯ To set the console font to the 8x8 size sc font, type:
$ consolechars -H 8 -f sc RET
To preview a PostScript or EPS image file in X, use ghostview. It takes a file name as an argument,
and it previews the contents of the file in a window, starting with its first page.
¯ To preview the file ‘/usr/doc/gs/examples/tiger.ps’, type:
$ ghostview /usr/doc/gs/examples/tiger.ps RET
Press Q to exit and press SPC to advance to the next page, if there is one.
NOTE: Some people prefer the gv tool as an alternate to ghostview; gv is used in much the same
way, though it has a different interface.
The Linux Cookbook: Tips and Techniques for Everyday Use
Debian: ‘xpdf’
WWW: http://www.foolabs.com/xpdf/
Debian: ‘gv’
WWW: http://wwwthep.physik.uni-mainz.de/˜plass/gv/
Use xpdf to preview a PDF file. Give the name of the PDF file to preview as an argument.
To exit xpdf, press Q; use the two magnifying-glass buttons to zoom the view closer in (+) or
further out (-), and use the left and right arrow buttons to move to the previous and next pages, if any.
Debian: ‘imagemagick’
WWW: ftp://ftp.wizards.dupont.com/pub/ImageMagick/
To view an image in X, use display, part of the ImageMagick suite of tools. It can recognize many
image formats, including FlashPix, GIF/GIF87, Group 3 faxes, JPEG, PBM/PNM/PPM, PhotoCD, TGA,
TIFF, TransFig, and XBM.
display takes as an argument the file name of the image to be viewed, and it displays the image in
a new window.
Menu items let you change the image size and otherwise change or transform the image display.
Choose Overview from the Help menu for an explanation of the various available display com-
mands.
Middle-click on the image to open a new window with a magnified view of the image centered where
you click. For example, middle-clicking on the sailboat image in the previous example will open a new
window that looks like this:
Finally, right-click on the image window for a pop-up menu containing a few of the most frequently-
used commands; to choose one of these commands, drag the mouse pointer over the command. Com-
mands in the pop-up menu include Quit, which exits display, and the Image Info, which displays
information about the image file itself, including number of colors, image depth, and resolution.
The following table describes some of the keyboard commands that work when displaying an image
in display.
C OMMAND D ESCRIPTION
SPC Display the next image specified on the command line.
The Linux Cookbook: Tips and Techniques for Everyday Use
The xpcd tool is an X client for viewing and browsing collections of Kodak PhotoCD images. To
browse the images on a Kodak PhotoCD, mount the CD-ROM (see Section 24.4.1 [Mounting a CD-
ROM], page 236), and then give the mount point as an argument to xpcd.
The Linux Cookbook: Tips and Techniques for Everyday Use
When you take an image file—such as one containing a digitized photograph or a picture drawn with a
graphics program—and you make changes to it, you are editing an image.
This chapter contains recipes for editing and modifying images, including how to convert between
image file formats. It also gives an overview of other image applications you might find useful, including
the featuresome GIMP image editor.
Many Linux tools can be used to transform or manipulate images in various ways. One very useful
package for both transforming images and converting between image formats is the netpbm suite of
utilities (see Section 19.2 [Scanning Images], page 202). Another is the ImageMagick suite of imaging
tools, of which mogrify is particularly useful for performing fast command line image transforms; use
it to change the size of, to rotate, or to reduce the colors in an image.
mogrify always takes the name of the file to work on as an argument, and it writes its changes to
that file. Use a hyphen (‘-’) to specify the standard input, in which case mogrify writes its output to
the standard output.
I’ll use the image ‘phoenix.jpeg’ in the examples that follow to give you an understanding of
how to use mogrify:
NOTE: You can also perform many of the image transformations described in the following sections
interactively with the GIMP (see Section 18.3 [Editing Images with the GIMP], page 198).
When mogrify resizes an image, it maintains the image’s aspect ratio, so that the ratio between the
width and height stays the same. To force a conversion to a particular image size without necessarily
preserving its aspect ratio, append the geometry with an exclamation point.
You can also specify the width or height by percentage. To decrease by a percentage, give the value
followed by a percent sign (‘%’). To increase by a percentage, give the value plus 100 followed by a
percent sign. For example, to increase by 25 percent, give ‘125%’.
¯ To increase the height of ‘phoenix.jpeg’ by 25 percent and decrease its width by 50 percent,
type:
NOTE: To view an image at a particular scale without modifying it, use display; when you resize its
window, you resize the image on the screen only (see Section 4.3.2 [Resizing a Window], page 53).
NOTE: After this command, the width of ‘phoenix.jpeg’ now exceeds its height, so to rotate it again
use ‘>’ instead of ‘<’.
Use the ‘-dither’ option to reduce the colors with Floyd-Steinberg error diffusion, a popular algo-
rithm for improving image quality during color reduction.
¯ To reduce the colors in ‘phoenix.jpeg’ to four and apply Floyd-Steinberg error diffusion, type:
$ mogrify -colors 4 -dither phoenix.jpeg RET
This transforms the original ‘phoenix.jpeg’ to:
Use the ‘-map’ option with a second file name as an argument to read the color map, or the set of
colors, from the second image and use them in the first image.
¯ To change the colors in the file ‘rainbow.jpeg’ to those used in the file ‘prism.jpeg’, type:
$ mogrify -map prism.jpeg rainbow.jpeg RET
Use the ‘-monochrome’ option to make a color image black and white.
¯ To make the color image ‘rainbow.jpeg’ black and white, type:
$ mogrify -monochrome rainbow.jpeg RET
If you have a PPM file, use ppmquant to quantize, or reduce to a specified quantity the colors in the
image—see the ppmquant man page for details (see Section 2.8.4 [Reading a Page from the System
Manual], page 28).
Because of differences in display hardware, the brightness of an image may vary from one computer
system to another. For example, images created on a Macintosh usually appear darker on other systems.
When you adjust the brightness of an image it is called gamma correction.
To adjust the brightness of an image, give the numeric level of correction to apply as an argument to
the ‘-gamma’ option. Most PC displays have a gamma value of 2.5, while Macintosh displays have a
lower gamma value of 1.4.
¯ To set the gamma correction of the image ‘rainbow.jpeg’ to .8, type:
$ mogrify -gamma .8 rainbow.jpeg RET
The Linux Cookbook: Tips and Techniques for Everyday Use
To annotate an image file with a comment, use mogrify with the ‘-comment’ option, giving the
comment in quotes as an argument to the option. This is useful for adding a copyright (or copyleft)
statement to an image, or for annotating an image file with a URL.
¯ To annotate the image file ‘phoenix.jpeg’, type (all on one line):
$ mogrify -comment "If you can read this,
you’re too close!" phoenix.jpeg RET
You won’t see the annotation when you view the image; it is added to the image header in the file.
You can, however, read image annotations with tools that display information about an image file, such
as display or the GIMP. To read annotations in JPEG files, you can also use the rdjpgcom tool—it
outputs any comments in the JPEG file whose file name is given as an argument.
¯
« ¨
To read any comments made in the image file ‘phoenix.jpeg’, type:
ª$
©
NOTE: Another method for writing comments in JPEG files is to use wrjpgcom, which is distributed
with rdjpgcom in the ‘libjpeg-progs’ package.
NOTE: The border is added to the outside of the existing image; the image is not cropped or reduced in
size to add the border.
The ‘-frame’ option works like ‘-border’, but it adds a more decorative border to an image.
¯ To add a decorative frame eight pixels wide and eight pixels high to ‘phoenix.jpeg’, type:
$ mogrify -frame 8x8 phoenix.jpeg RET
NOTE: In this example, three JPEGs were read and output to a PNG file; to specify the format to use in
the output, give the appropriate file extension in the output file name.
You can specify the percentage to blend two images together with the ‘-blend’ option. Give the
amount to blend the second image into the first (as a percentage) as an argument to the option.
¯ To combine the image files ‘phoenix.jpeg’ and ‘ashes.jpeg’ so that the blended image
contains 70 percent of the second image, type:
$ combine -blend 70 ashes.jpeg phoenix.jpeg picture.jpeg RET
This command combines the two images and writes a new image file, ‘picture.jpeg’, whose
contents contain 70 percent of the first image.
NOTE: Use ‘-blend 50’ to blend the two source files equally.
The Linux Cookbook: Tips and Techniques for Everyday Use
NOTE: ‘xmorph’ is a tool for morphing images; see Section 18.4 [Interactive Image Editors and Tools],
page 199.
Use convert to convert the file format of an image. Give the name of the file to convert as the first
argument, and the destination file as the second argument. When you convert a file, the original is not
altered.
To specify the file type to convert to, use that file type’s standard file extension in the file name of the
converted file.
¯ To convert the JPEG file ‘phoenix.jpeg’ to a PNG image, type:
$ convert phoenix.jpeg phoenix.png RET
This command converts the JPEG image ‘phoenix.jpeg’ to PNG format and writes it to a new
file, ‘phoenix.png’.
The following table lists the file extensions to use and describes their format. (The convention is to
give extensions in all lowercase letters.)
F ILE E XTENSION I MAGE F ORMAT
bmp Microsoft Windows bitmap image.
cgm Computer Graphics Metafile format.
cmyk Raw cyan, magenta, yellow, and black bytes.
eps Adobe Encapsulated PostScript.
fax Group 3 fax format.
fig TransFig image format.
fpx FlashPix format.
gif CompuServe Graphics Interchange Format, version GIF89a
(usually pronounced “giff,” rhyming with “biff”).
gray Raw gray bytes.
jpeg and jpg Joint Photographic Experts Group JFIF format (usually pronounced
“jay-peg”).
pbm Black and white portable bitmap format.
pcd Kodak PhotoCD format, 512x768 pixels maximum resolution.
pcl Page Control Language format.
pcx ZSoft IBM PC Paintbrush format.
pdf Adobe Portable Document Format.
pict Apple Macintosh QuickDraw format.
png Portable Network Graphics format (usually pronounced “ping”).
pnm Portable “anymap” format.
ppm Color portable pixmap format.
ps Adobe PostScript format.
rgb Raw red, green, and blue bytes.
tga TrueVision Targa image format.
tiff and tif Tagged Image File Format (usually pronounced “tiff”).
xbm X Window System bitmap format.
xpm Color X Window System pixmap format.
xwd Color X Window System window “dump” file format.
When converting a file to JPEG format, be sure to use the ‘-interlace NONE’ option to make
sure the resultant JPEG image is non-interlaced—unless, of course, you want an interlaced image; an
interlaced image is drawn in multiple passes, and is often used on the Web where a reader may view the
low-resolution image consisting of early passes before the entire image is downloaded. A non-interlaced
image is drawn in one single pass.
For example, use convert to convert a PNM file to non-interlaced JPEG, while sharpening it,
adding a border, and adding a copyright statement.
¯ To convert the PNM file ‘pike.pnm’ to non-interlaced JPEG while sharpening the image by 50
percent and adding both a 2x2 border and a copyright comment, type:
$ convert -interlace NONE -sharpen 50 -border 2x2
-comment ’copyright 1999 MS’ pike.pnm pike.jpeg RET
This command writes its output to a file ‘pike.jpeg’. Notice that the options ‘-border’ and
‘-comment’ were previously described for the ‘mogrify’ tool. Some ImageMagick tools share com-
mon options, which is useful if you are making multiple changes to an image file at once; only one tool
is needed for the job.
The Linux Cookbook: Tips and Techniques for Everyday Use
NOTE: Some image formats are “lossy,” in that some image information is lost when you convert to
it. For example, the JPEG format is a lossy format that is usually used for photographic images. If you
convert a file from its source PNM format to JPEG and then back to PNM, the resultant PNM will not be
identical to the original source PNM.
To convert image files interactively, use the GIMP to open the image, and then choose ‘Save as’
from the File menu, and select the file type to use; see Section 18.3 [Editing Images with the GIMP],
page 198.
Debian: ‘gimp’
Debian: ‘gimp-manual’
WWW: http://www.gimp.org/
The GIMP (GNU Image Manipulation Program) is an all-encompassing image-editing and manipulation
program that lets you paint, draw, create, and edit images in complex ways. Using gimp you can also
convert image files, retouch and edit photographic images, and browse collections of images.
The GIMP comes with hundreds of tools, filters, fonts, and other goodies installed. Here is a partial
list of its features:
¯ Contains a full suite of painting tools, including Brush, Pencil, Airbrush, and Clone.
¯ Includes a full suite of image selection, transformation, and manipulation tools, including a gradient
editor, color blending, and special effects.
¯ Allows for large images, with their size being limited only by available disk space.
¯ Provides high-quality anti-aliasing.
NOTE: To learn the basics of the GIMP, consult The GIMP User’s Manual and the other documentation
and resources on the Web at http://www.gimp.org/. You can also install the manual on your
system; it comes in the Debian ‘gimp-manual’ package.
Use import, part of the ImageMagick suite, to take a screen shot in X. import can capture the entire
screen, a single window, or an arbitrary rectangular area, taking as an argument the name of the file
to save to. As with other ImageMagick tools, the image format of the output file depends on the file
extension you specify: ‘.eps’ for EPS, ‘.tiff’ for TIFF, ‘.jpeg’ for JPEG, and so on. (For a
complete list, see Section 18.2 [Converting Images between Formats], page 196).
After you give the command, the mouse pointer changes to a set of cross-hairs. You then use the
mouse to specify which window to take the shot of, as follows:
¯ Left-click on a window to capture it.
¯ Left-click on the root window to capture the entire screen.
¯ Left-click and drag the mouse across an area of the screen to form a rectangular selection outline;
release the mouse button to capture the selected area.
When you specify a window, import captures only the window’s contents; use the ‘-frame’ option
to include the window manager frame in the image.
¯ To capture a particular window, including its window manager frame, and write it to a PNG-format
file, first type:
$ import -frame session-1.png RET
¯ Then, left-click on the window you want to capture.
In this example, the capture is saved to a file called ‘session-1.png’.
NOTE: The system bell rings once when the screen capture starts, and twice when the captures finishes.
¯ To take a screen shot of the fourth virtual console, and save it to a file called ‘screenshot’, type:
$ cat /dev/vcs4 > screenshot RET
NOTE: You must have superuser privileges to access these files (see Appendix A [Administrative Issues],
page 315).
The Linux Cookbook: Tips and Techniques for Everyday Use
Take the screen shot from a virtual console different from the one you want to take a shot of; if you
try to take it from the same console you want to capture, the command line you give will be included in
the shot! (Kind of like having your thumb in front of the lens while taking a photograph.)
Screenshots taken of virtual consoles, as shown here, are saved as text files; you can’t take screen
shots of virtual consoles when graphics are displayed.
SANE, “Scanner Access Now Easy,” is the de facto Linux scanner interface; use it to scan an image with
a scanner and save it to a file.
SANE works with a wide array of scanning hardware, but make sure the scan-
ning hardware you want to use is compatible by checking the Hardware HOWTO
(http://linuxdoc.org/HOWTO/Hardware-HOWTO.html) and SANE’s list of
supported scanners (http://www.mostang.com/sane/sane-backends.html).
Once you have SANE running, you can scan images with SANE-aware applications like the GIMP
(see Section 18.3 [Editing Images with the GIMP], page 198).
The following recipes describe use of the command-line scanimage tool, which comes with the
SANE package.
NOTE: As the acronym implies, getting a scanner to work on a Linux system hasn’t always been smooth
going. The SANE interface is completely open, and its developers are making sure that it is generalized
enough to be implementable on any hardware or operating system.
ª$
©
In this example, there’s one scanning device on this system, a UMAX brand scanner that can be
specified to scanimage by giving its device name, ‘umax:/dev/sgb’, as an argument to the ‘-d’
option.
To list the available resolutions and options supported by a particular device, use the ‘--help’ option
along with the ‘-d’ option followed by its device name.
¯ To list available options supported by the device listed in the previous example, type:
$ scanimage --help -d ’umax:/dev/sgb’ RET
NOTE: For all scanimage commands, specify the scanner device you want to use by including the
‘-d’ option with the device name.
19.2.2 Testing a Scanner
To run diagnostic tests on a scanner to make sure that it can be properly read from, use scanimage
with the ‘--test’ option.
¯ To test the UMAX scanner listed previously, type:
$ scanimage --test -d ’umax:/dev/sgb’ RET
Use scanimage to scan an image. Most scanners let you specify the x and y values, in pixels, for
the image size to scan, starting from the top-left corner of the scanner bed. Give these coordinates as
arguments to the ‘-x’ and ‘-y’ options. Also, give an argument to the ‘--resolution’ option to
specify the scan resolution, given in dpi (“dots per inch”). Common resolution values include 72, 120,
300, and 600 dpi; 72 dpi is the most popular resolution for use on the Web or for viewing on screen, and
204 dpi is often used for images that you want to send on a fax machine.
Scanned output is sent to standard output, so to scan an image to a file, redirect the standard output.
scanimage outputs images in the PNM (“portable anymap”) formats, so make sure that you have
the ‘netpbm’ package (installed on most Linux systems by default); it’s a useful collection of tools for
converting and manipulating these formats. The formats output by scanimage are as follows:
F ORMAT D ESCRIPTION
PPM Color images.
PBM Black and white images.
PGM Grayscale images.
Use the ‘--mode’ option to specify the format of the output, followed by one of the following
arguments: ‘color’ for color PPM, ‘gray’ for PGM grayscale, or ‘lineart’ for black and white
PBM. Each scanner has a default mode; for most color scanners, the default mode will be ‘color’.
¯ To make a 72 dpi scan of a color image 200 pixels wide and 100 pixels tall, using the UNIX scanner
from previous examples, and writing to a file called ‘scan.ppm’, type:
$ scanimage -d umax:/dev/sgb --resolution 72 -x 200 -y 100 >
scan.ppm RET
¯ To make a 300 dpi scan of a black and white image 180 pixels wide and 225 pixels tall, using the
UMAX scanner from previous examples, and writing to a file called ‘scan.pbm’, type:
$ scanimage -d umax:/dev/sgb --resolution 300 --mode lineart
-x 180 -y 225 > scan.pbm RET
NOTE: The command lines in this recipe are split across two lines because they’re too long to fit on one,
but type these commands on one long line.
Once the image has been scanned and written to a file, you can edit it just as you would any image.
There are two methods to extract an image from Kodak PhotoCD (“PCD”). If you are browsing the disc
This is a proprietary scanned image format from Kodak, which is a current standard for scanning film images to digital.
The Linux Cookbook: Tips and Techniques for Everyday Use
with the xpcd tool, then choose an image, extract a copy at the desired resolution, and save it to a file,
as described in Section 17.5 [Browsing PhotoCD Archives], page 187.
You can also use pcdtoppm on a PCD file directly to extract an image at a given resolution and save
it to a file in PPM format. Use the ‘-r’ option to specify the resolution to extract, given as a numeric
argument from 1 (lowest resolution) to 5 (highest); if this option is omitted, a value of 3 is assumed. Also
give as arguments the name of the PCD file to read from and the name of the PPM file to write to.
¯ To extract the highest resolution from the file ‘slack.pcd’ and save it to a PPM file named
‘slack.ppm’, type:
$ pcdtoppm -r5 slack.pcd slack.ppm RET
Extracted PhotoCD images are known to sometimes have a kind of “green haze” over them; to remove it,
open the image in the GIMP and adjust the color levels with the Auto Levels function. This technique,
adapted from a tip for using PhotoCD by Philip Greenspun (http://philip.greenspun.com/),
works well for improving any scanned or imported image.
¯ To remove the “green haze” from a PhotoCD image, do the following:
¯ First, open the extracted image in the GIMP (see Section 18.3 [Editing Images with the GIMP],
page 198).
¯ Then, click through the Image menu to the Colors submenu and then to the Levels sub-
menu, and choose Auto Levels.
¯ Click OK in the Levels window to accept the changes.
20 PostScript
Debian: ‘gs’
Debian: ‘psutils’
WWW: ftp://www.gnu.org/pub/gnu/ghostscript/
WWW: ftp://ftp.dcs.ed.ac.uk/pub/ajcd/
WWW: http://www.cappella.demon.co.uk/tinyfiles/tinymenu.html
PostScript is a programming language, used to describe the way a “page” (usually a physical sheet of
paper) should look. PostScript files are text files containing the PostScript commands for drawing images
to be printed on pages.
Like plain text files, PostScript files are commonly found on the Internet (and are used by commercial
printers) because, as with plain text, they can be shared across platforms and hardware without difficulty.
The same PostScript file can be output on a high-end display or printed on a low-end printer, to the best
of that hardware’s capability. PostScript is a compact and elegant format.
While it’s possible to write directly in the PostScript language, and some people have become adept
at programming PostScript, so many tools and applications convert files to and from PostScript that you
don’t have to. See Section 15.2 [Converting Plain Text for Output], page 159, for a way to convert plain
text into PostScript.
Ghostscript is a free implementation of the PostScript language. The gs tool is a Ghostscript inter-
preter that is used to convert files from PostScript to other formats, usually for printing to a non-PostScript
printer (see Section 25.3.1 [Preparing a PostScript File for Printing], page 241). The ghostview tool
is used to preview PostScript files on the screen (see Section 17.1.2 [Previewing a PostScript File],
page 183).
EPS, or Encapsulated PostScript, is a file format that describes the contents of a box within a page.
EPS files can be embedded in the page of a PostScript file, and are therefore commonly used when
inserting an illustration into a document (for example, all of the illustrations in the Cookbook are EPS
format files). You can view and print EPS files just as you would PostScript files.
This chapter includes recipes for formatting and manipulating PostScript files. Recipes are separated
according to whether they work on the individual, logical pages in a PostScript file (the numbered pages
in the file that are not necessarily the physical pages of output), and those that work on the entire file as
a whole.
Unless otherwise indicated, the tools in this chapter are part of Angus Duggan’s PSUtils package.
These tools can be useful for other purposes than those described below; see their respective man pages
for more details.
¯ To output as PostScript the pages 137 to 146 of the file ‘abstract.dvi’ to the file
‘abstract.ps’, type:
$ dvips -pp137-146 -o abstract.ps abstract.dvi RET
To specify the paper size, give the name of a standard paper size as an argument to the ‘-p’ option:
a3, a4, a5, b5, letter, legal, tabloid, statement, executive, folio, quarto, or 10x14. You can also specify
any height and width with the ‘-h’ and ‘-w’ options; units can be specified in centimeters (followed by
‘cm’) or inches (followed by ‘in’). If no size is specified, psnup assumes a paper size of a4.
Use the ‘-l’ option when pages are in landscape orientation (rotated 90 degrees counter-clockwise
from portrait orientation), and ‘-r’ when pages are in seascape orientation (rotated 90 degrees clockwise
from portrait orientation).
Pages are placed in “row-major” layout in the output file, where logical pages are placed in rows
across the page. Use the ‘-c’ option to specify a “column-major” layout, where logical pages are placed
in columns down the page. Scale the size of the pages by giving a percentage to multiply the page size
by as an argument to the ‘-s’ option; for example, ‘-s .5’ scales pages to 50 percent of their original
size.
To draw a border around each page, specify the border’s width in points as an argument to the ‘-d’
option (if no width is specified, a value of 1 is assumed).
By default, psbook uses one signature for the entire file. If the file doesn’t contain a multiple of four
pages, it adds blank pages to the end.
To specify the size of the signature to use—in other words, the number of pages that will appear on
a single piece of paper—give the number as an argument to the ‘-s’ option. Signature size is always a
multiple of four.
¯ To rearrange the pages of file ‘newsletter.ps’ into an eight-sided signature and write it to
‘newsletter.bound.ps’, type:
$ psbook -s8 newsletter.ps newsletter.bound.ps RET
NOTE: As of this writing, psmerge only works with PostScript files that were made with the same
application—which means, for example, that you can merge multiple files made with TEX, or multiple
files made with xfig, but not a combination of the two.
ª$
©
20.3 Converting PostScript
These recipes show how to convert PostScript files to other formats. See also the recipes for preparing
PostScript files for printing, Section 25.3.1 [Preparing a PostScript File for Printing], page 241.
This chapter covers the basic control of audio on Linux-based systems, including how to adjust the audio
mixer and how to play and record sound files using basic tools. You can also play and record audio with
snd (see Chapter 23 [Editing Sound Files], page 225) and many other sound applications.
For purposes of this discussion, I will assume you are using the ALSA sound driver on your system
and that you have sound working properly; unlike the standard Open Sound System driver (OSS/Linux),
the ALSA driver is made entirely of free software. It is becoming the de facto choice for musicians who
use Linux.
NOTE: Most systems come configured so that you must be the superuser to be able to use sound devices,
including audio CDs. If this is the case on your system, ask your administrator to give you access to
these devices, typically by adding you to the audio group (see Section 6.1 [Groups and How to Work
in Them], page 75).
The play tool distributed with sox (a sound file translation tool) can recognize and play many audio
formats, including WAV, VOC, AU, AIFF, and SND format files, as well as audio CD-format files and
various raw binary files; just about the only common audio formats it can’t handle are MP3 and MIDI
files, which are discussed in the sections to follow.
¯ To play the file ‘pentastar.aiff’, type:
$ play pentastar.aiff RET
NOTE: Before you begin playing sound, make sure you’ve set the master and PCM volume levels with
the mixer (see Section 21.2 [Adjusting the Audio Controls], page 213). The most common reason for no
sound being produced when you try to play sound is not having the volume turned up!
ALSA comes with aplay, a tool for playing sound files that is similar to play, but does not recog-
nize as many formats.
The playmidi tool is for playing MIDI files; give the name of the MIDI file to play as an argument.
¯ To play the MIDI file ‘copa-cabana.mid’, type:
$ playmidi copa-cabana.mid RET
If you have a non-MIDI sound card, you can still play MIDI files by giving the ‘-f’ option, which
sends the MIDI output to the FM synthesizer on the sound card, which in turn plays it using FM patches
that come with the playmidi distribution.
¯ To play the MIDI file ‘copa-cabana.mid’ on a non-MIDI sound card, type:
$ playmidi -f copa-cabana.mid RET
To record sound, first select an input device as a source for recording. Sound cards may have MIC and
LINE IN jacks, as well as connections to the CD-ROM drive, all of which are sound inputs that can be
recording sources. When you select a device for capture, your recording will come from this source.
Recording occurs from the currently active input, if any, which must be set with the mixer; unmute it
and set its volume level before you begin recording. (Be sure to turn the volume on your speakers all the
way off, or you’ll get feedback.)
To record audio to a file, use the rec tool. It can write many audio file formats, either to a format
you specify with the ‘-t’ option, or by determining the format to use based on the file name extension
you give the output file (see Section 21.1 [Sound File Formats], page 213). Type C-c to stop recording.
Give the name of the sound file to record as an argument; if a ‘.wav’ file is specified, it records a
simple monaural, low-fidelity sound sample by default.
¯ To record a simple WAV sample from the microphone and save it to a file called ‘hello.wav’,
type:
$ rec hello.wav RET
This command begins an 8,000 Hz, monaural 8-bit WAV recording to the file ‘hello.wav’, and
keeps recording until you interrupt it with C-c. While the default is to make a low-fidelity recording—
8,000 Hz, monaural 8-bit samples—you can specify that a high-fidelity recording be made. (But remem-
ber that high-fidelity recordings take up much more disk space.)
To make a stereo recording, use the ‘-c’ option to specify the number of channels, giving 2 as the
argument. To make a 16-bit recording, give ‘w’ (“wide”) as the argument to the ‘-s’ (“sample size”)
option.
Set the recording sample rate by giving the samples per second to use as an argument to the ‘-r’
option. For CD-quality audio at 44,100Hz, use ‘-r 44100’.
Finally, to record a file in a particular format, either give the name of the format as an argument to
the ‘-f’ option, or use the traditional file name extension for that format in the output file name (see
Section 21.1 [Sound File Formats], page 213).
¯ To make a high-fidelity recording from the microphone and save it to a WAV-format file called
‘goodbye.wav’, type:
$ rec -s w -c 2 -r 44100 goodbye.wav RET
¯ To make a sound recording in the CD audio format, and write the output to a file called
‘goodbye.cdr’, type:
$ rec goodbye.cdr RET
NOTE: When you’re not recording sound, keep the inputs muted (see Section 21.2.3 [Muting an Audio
Device], page 214); this way, you can have a microphone plugged in without having feedback when
playing sounds. Also, make sure the volume levels are not set too high or too low when recording;
getting the right level for your microphone or other input device may take some initial adjustment.
Like play, rec is part of the sox toolkit.
These recipes describe various ways to play audio CDs using the command-line tools found in the
‘CDTOOL’ suite. Other CD audio tools, including X clients, are listed in Section 22.4 [Other Audio
CD Applications], page 223.
$ cdir RET
unknown cd - 43:14 in 8 tracks
5:15.00 1
5:50.40 2
5:29.08 3
3:50.70 4
4:17.00 5
5:56.15 6
7:13.40 7
5:19.22 8
ª
$
©
In this example, the CD contains eight tracks, with a total of 43 minutes and 14 seconds play time.
22.1.6 Ejecting an Audio CD
Use cdeject to eject the disc in the CD-ROM drive. If the disc is currently playing, play will stop and
the disc will eject.
¯ To eject a CD, type:
$ cdeject RET
NOTE: This command will also eject a CD-ROM (data CD), if the CD-ROM is not currently mounted
(see Section 24.4 [CD-ROMs], page 236).
Two tools used for sampling (sometimes called “ripping”) data from an audio CD are cdda2wav and
cdparanoia. Both can retrieve single tracks or entire disks; the former is the archetypal CD audio-
sampling tool for Linux, and should be used when speed is more important than sound quality. The
latter does various extra checks for the paranoid, and should be used when an absolutely perfect copy is
necessary—at the expense of speed. cdda2wav is perfectly capable of creating a digitally perfect audio
sample; cdparanoia is useful for when your original CD may have scratches (its scratch detection
capability can attempt to “hold sync” across the scratch), or for when you are using a less-than-optimal-
quality CD-ROM drive.
With cdda2wav, you specify the track number to be retrieved as an argument to the ‘-t’ option; use
‘x’ to specify a CD-quality retrieval, and give the name of the CD-ROM device with the ‘-D’ option—
unless you have multiple CD-ROM drives installed, this is almost certainly going to be ‘/dev/cdrom’.
By default, files are written as WAV format files; use the ‘-O’ option followed by ‘cdr’ to write
the files in CD audio format. ‘.cdr’ files are useful for burning an audio CD containing the files as
tracks (discussed in the following section), and ‘.wav’ files are useful for converting to MP3 format (see
Section 23.3.1 [Making an MP3 File], page 229). You can convert either format to the other at a later
time with sox—see Section 23.3 [Converting Sound Files], page 228.
¯ To copy track seven of an audio CD to a CD-quality WAV file in the current directory, type:
$ cdda2wav -t7 -d0 -x -D /dev/cdrom RET
¯ To copy all tracks on an audio CD to separate CD-quality CD audio-format files, type:
$ cdda2wav -D /dev/cdrom -x -O cdr -d0 -B RET
For more reliable sampling, use cdparanoia. Give the range of audio tracks to sample as an
argument (with no arguments, it samples the entire disc). Use the ‘-w’ option to specify WAV format
output.
¯ To sample the third track from a scratched audio CD in the default CD-ROM drive using “paranoid”
data verification, and write the output to a WAV format file in the current directory, type:
$ cdparanoia -w 3-3 RET
¯ To sample the entire audio CD using “paranoid” data verification, type:
$ cdparanoia -w -B RET
¯ To sample the entire audio CD using less-than-maximum “paranoid” data verification, without
checking for scratches, and saving each song as a separate raw audio-format file in the current
directory, type:
$ cdparanoia -B -Y -X RET
The Linux Cookbook: Tips and Techniques for Everyday Use
NOTE: Sampling an entire audio CD can use a lot of disk space; most people delete the ‘.cdr’ or
‘.wav’ files as soon as they make MP3s or burn an audio CD-R from the data.
Use ‘cdrecord’ to write (or “burn”) audio files to a blank CD-R disc. You will need a CD-R drive
and the audio files must be in CD-DA CD audio format (they usually have a ‘.cdda’ or ‘.cdr’ file
name extension).
Specify the CD-R drive with the special ‘dev’ argument, which is given in this form:
‘dev=scsibus,target,lun ’
where scsibus is the number of the SCSI bus (0 for the primary bus), target is the SCSI target ID (usually
a number from 1 to 6), and lun is its LUN number (most always 0).
Use the ‘speed’ argument to set the speed factor for writing data: give ‘speed=2’ to specify double
speed or ‘speed=4’ to specify quad speed.
Use the ‘-dummy’ option to run with the drive laser turned off, so no actual burning takes place; this
is useful when you are first using a CD-R drive and need to test your configuration to make sure you’ve
got it right. Another useful option is ‘-v’, which gives a more verbose message output.
Give the names of the audio files to burn, in the order that they should appear on the disc, as arguments
to the ‘-audio’ option. The files are written in CD-DA CD audio format, and they should contain 16-bit
stereo at 44,100 samples/second (the ‘.cdr’ or ‘.cdda’ files meet this criterion).
¯ To burn the file ‘symphony.cdr’ to the disc in the CD-R drive whose target ID is 2 on the primary
SCSI bus, type:
$ cdrecord dev=0,2,0 -audio symphony.cdr RET
¯ To burn all the files in the current directory ending with a ‘.cdr’ extension at double speed to the
CD-R drive whose target ID is 2 on the primary SCSI bus, and give verbose output, type:
$ cdrecord dev=0,2,0 speed=2 -v -audio *.cdr RET
¯ To run a test burn of the file ‘symphony.cdr’ to the disc in the CD-R drive whose target ID is 6
(LUN 1) on the primary SCSI bus, type:
$ cdrecord dev=0,6,1 -dummy -audio symphony.cdr RET
When you use wildcards for files, as in the second-to-the-last example, the shell expands the files in
alphabetical order. To write a group of tracks in a particular order without specifying all of their names
as arguments, rename them so that their names begin with numbers that correspond to the order you want
to write them in (see Section 5.5 [Moving Files and Directories], page 68).
For example, if you have the three files ‘morning-song.cdr’, ‘midday-song.cdr’,
and ‘evening-song.cdr’, and you want to write them in that order, rename the files to
‘01-morning-song.cdr’, ‘02-midday-song.cdr’, and ‘03-evening-song.cdr’;
otherwise, if you specify them as ‘*.cdr’, the shell will sort their names so that they will
be written to CD-R in the order of ‘evening-song.cdr’, ‘midday-song.cdr’, and
‘morning-song.cdr’—exactly the opposite of what was intended!
To write a disc containing both data and audio tracks, first specify the file for the data track (it
should contain a filesystem image in either ISO 9660 or Rock Ridge format), and then follow it with the
‘-audio’ option and the names of the audio tracks to use. The resulting CD-R will be both mountable
as a data CD and playable on audio CD players (the first track on the disc, the data track, will be skipped
when playing the audio).
You can also use this tool with a CD-RW drive and write to a CD-RW disc.
¯ To burn the data track ‘band-info’ and all the audio tracks in the current directory with a
‘.cdda’ extension to the CD-R drive whose target ID is 2 on the primary SCSI bus, type:
$ cdrecord dev=0,2,0 band-info -audio *.cdda RET
NOTE: When writing an audio CD, you should have as few processes running as possible. If cdrecord
has to pause even momentarily to let the system shuffle other processes, the CD-R could be ruined! For
this reason, it is advisable to avoid switching between consoles—or between windows, if running X—
during the CD-R burning process.
Snd is a sound-file editing environment for X, and aims to be for sound what Emacs is to text. (And it
uses Emacs-style key bindings.)
You’ll find a complete manual for it in the ‘/usr/doc/snd’ directory; this section explains how to
use Snd to work with selections from sound files.
To open a sound file in Snd, give the name of the file to be opened as an argument to snd.
¯ To open the sound file ‘mixdown.wav’ in Snd, type:
$ snd mixdown.wav RET
This command starts Snd with a WAV file called ‘mixdown.wav’:
Making a selection of a sound file in snd is similar to selecting text in Emacs; you can mark a section
of a sound file or recording you’ve made in Snd by left-clicking and dragging across the area with the
mouse. The area you drag across becomes shaded and is called the selection. Once you select a portion
of the sound, any effect you choose works on that selection. You can also cut and paste selections of the
sound you are editing into other sound buffers.
The xwave tool (and many others, no doubt) have similar capabilities and functions (see Section 23.4
[Other Tools for Sound Editing], page 230).
The “Sound eXchange” tool, sox, is a sound sample translator. It reads sound as files or standard input
and outputs the sound either to a file or standard output, while translating in between. You can use sox
to convert sound files between formats or process sounds with special effects. This section describes
some of the special effects you can apply to sound files with sox.
When applying an effect, the original file is never altered. You must specify an output file, or use ‘-’
to indicate the standard output, specifying the output format with ‘-t’. You can only apply one effect
with each sox command; thus, to add both echo and reverb to a sound file, you would need to issue two
sox commands.
The amount and levels applied for each effect will vary with every situation. As such, consider the
following recipes guidelines only for using the options; you will probably end up experimenting a bit to
get your intended effect for any particular sound file.
Almost all of the sound effects are applied by specifying the input and output file arguments, followed
by the name of the effect to use and any options the effect takes (with notable exceptions, like the ‘-v’
option for changing the amplitude of a file).
NOTE: For more information on the effects Sox can do, see the various files in ‘/usr/doc/sox/’,
and read the sox man page (see Section 2.8.4 [Reading a Page from the System Manual], page 28).
Use sox with the ‘stat’ option and ‘-v’ to determine the largest possible value that can be used
before distortion or clipping occurs (it performs a statistical analysis on the file and outputs a numeric
value). This value comes in handy when you want to raise a file’s volume as high as possible without
ruining its fidelity.
¯ To raise the volume of the file ‘quit.cdr’ as high as possible without distortion, type:
« ¨
$ sox quiet.cdr loud.cdr stat -v RET
3.125
$ sox -v 3.125 quiet.cdr loud.cdr RET
ª$
©
The preceding example writes a new file, ‘loud.cdr’.
Use sox for most sound-file conversions. Give as arguments the name of the input file and the name of
the output file to write to; use a file name extension specifying the sound format for the output file (see
Section 21.1 [Sound File Formats], page 213).
¯ To convert the file ‘new.wav’ to an audio CD format file, type:
$ sox new.wav new.cdr RET
This command writes a new file, ‘new.cdr’, in the audio CD format; the original file, ‘new.wav’,
is not altered.
You may sometimes need to specify additional options, such as with raw audio files where the sam-
pling rate and other properties must be specified.
¯ To convert all of the raw audio files in the current directory to audio CD format files, type:
$ for i in *.raw RET
{ RET
sox -s -w -c2 -r 44100 $i -x $i.cdr RET
} RET
This command writes all of the ‘.raw’ files to new files of the same name but with a ‘.cdr’ ex-
tension. You could then use cdrecord to burn an audio CD with the ‘.cdr’ files (see Section 22.3
[Writing an Audio CD-R], page 222).
To convert a file to a particular format without using the standard extension, specify the format to
write to with the ‘-t’ option.
¯ To convert the file ‘new.wav’ to the audio CD format and write output to a file named
‘cd-single’, type:
$ sox new.wav -t cdr cd-single RET
The process of making an MP3 file from a raw audio or WAV format audio file is called “encoding”
an MP3 file; programs that do this are MP3 encoders. This is not so much a recording process as it is
a conversion process: existing audio is converted to an MP3 file. (To make MP3 files from your own
recordings, make the recording as a CD-quality WAV file, and then convert that.)
Unfortunately, the algorithm for encoding MP3 is patented, and all software which uses it must pay
a license fee—including free software. This restriction makes it difficult for people to create a free
software MP3 encoder, and it is the reason why some free software and open source groups advocate the
development of a high-quality compressed audio format to replace MP3.
A workaround is presented in the form of LAME (“LAME Ain’t an MP3 Encoder”). LAME isn’t
an MP3 encoder, but it is a free software patch file (see Section 8.4.3 [Patching a File with a Difference
Report], page 91) designed to work with the sample source code distributed by the patent holders of the
MP3 encoding process.
This means that you can download both separately and combine them to get a working MP3 encoder
called notlame, perhaps the fastest (yes, encoding MP3s is a slow process) encoder currently available
for Linux. When you visit the LAME Project at http://www.sulaco.org/mp3/, you’ll find a
link to download a pre-assembled notlame binary from a site in Australia, where the patent laws do
not apply.
The notlame encoder takes two arguments: the name of the input file and the name of the output
file.
¯ To encode an MP3 file from a WAV file called ‘september-wind.wav’, type:
$ notlame september-wind.wav september-wind.mp3 RET
It usually takes some time to encode an MP3 file; when notlame is encoding a file, it continually
outputs the current percentage of completion.
NOTE: Scripts on the download site show how to encode multiple WAV files and how to decode all of
the tracks on an audio CD.
Ogg Vorbis is one such format; see http://www.vorbis.com/.
The Linux Cookbook: Tips and Techniques for Everyday Use
To convert an MP3 file to another format, use mpg321 (or another command-line MP3 player) to play
the file to the standard output, and then use sox to read the resultant raw audio and write it to another
file with a specified input format.
¯ To convert the MP3 file ‘remix.mp3’ to a WAV file ‘remix.wav’, type:
$ mpg321 -b 10000 -s remix.mp3 | sox -t raw -r 44100 -s -w
-c 2 - remix.wav RET
ª
$
©
This example shows that three filesystems are mounted on the system—the filesystem mounted on ‘/’
is at 23 percent capacity, the filesystem mounted on ‘/usr’ is at 26 percent capacity, and the filesystem
mounted on ‘/home/webb’, a home directory, is at 87 percent capacity.
¯
« ¨
To output the disk usage for the directory tree whose root is the current directory, type:
$ du RET
8 ./projects/documentation
12 ./projects/source
4 ./projects/etc
24 ./projects
3 ./tmp
27 .
ª$
©
This example shows two subdirectories in the directory tree: ‘projects’ and ‘tmp’; ‘projects’
contains three additional directories. The amount of disk space used by the individual directories is the
total on the last line, 27K.
By default, output is in 1K blocks, but you can specify another unit to use as an option: ‘-k’ for
kilobytes and ‘-m’ for megabytes.
¯ To output the disk usage, in kilobytes, of the ‘/usr/local’ directory tree, type:
$ du -k /usr/local RET
¯ To show the number of megabytes used by the file ‘/tmp/cache’, type:
$ du -m /tmp/cache RET
Use the ‘-s’ option (“summarize”) to output only the last line containing the total for the entire
directory tree. This is useful when you are only interested in the total disk usage of a directory tree.
¯ To output only the total disk usage of the ‘/usr/local’ directory tree, type:
$ du -s /usr/local RET
¯ To output only the total disk usage, in kilobytes, of the ‘/usr/local’ directory tree, type:
$ du -s -k /usr/local RET
To mount a floppy to a specific directory, use mount and give as arguments the device name of the
floppy drive (usually ‘/dev/fd0’ for one-floppy systems) and the name of the directory to mount to.
¯ To mount the floppy in the first floppy drive to ‘˜/tmp’, type:
$ mount /dev/fd0 ˜/tmp RET
Once you have mounted a floppy, its contents appear in the directory you specify, and you can use
any file command on them.
¯ To list the contents of the base directory of the floppy mounted on ‘/floppy’, type:
$ ls /floppy RET
¯ To list the contents of the entire directory tree on the floppy mounted on ‘/floppy’, type:
$ ls -lR /floppy RET
NOTE: You can copy files to and from the directory tree that the floppy is mounted on, make and remove
directories, and do anything else you could on any other directory tree. But remember, before you remove
it, you must first unmount it.
NOTE: You can’t unmount a disk if your current working directory, the directory you are in, is some-
where in that disk’s directory tree. In this case, trying to unmount the disk will give the error that the
‘/floppy’ filesystem is in use; change to a different directory that isn’t in the ‘/floppy’ directory
tree, and then you can unmount the disk.
Sometimes when you unmount a floppy, the light on the floppy drive will go on and remain on for
a few seconds after it has been unmounted. This is because Linux sometimes keeps changes to files in
memory before it writes them to disk; it’s making sure that the files on the floppy are up-to-date. Simply
wait until the light goes off before you remove the floppy from the drive.
This works if your administrator has set up the floppy drive filesystem for user access—see Section A.3.2 [Letting Users
Access Hardware Peripherals], page 318.
This is sometimes called being “under the mount point” of the disk.
The Linux Cookbook: Tips and Techniques for Everyday Use
24.4 CD-ROMs
As with a floppy disk, before you can use a data CD (compact disc) on your system, you must first mount
it on an empty directory. You then unmount it from the directory before you can eject the CD from the
CD-ROM drive (you can also eject the disc using software—see Section 22.1.6 [Ejecting an Audio CD],
page 221).
NOTE: To use audio CDs, see Chapter 22 [Audio Compact Discs], page 219.
The usual way to print on a Linux system is to send a print job to the printer with lpr, as described
below in Section 25.1.1 [Sending a Print Job to the Printer], page 237.
But you don’t always send a file straight to the printer—sometimes you may want to add special
things to it before you print it, such as headers or graphic trim. For example, you might want to split a
text file into pages and add a header to the top of each page containing the file name and page number;
all of this is described in Chapter 13 [Formatting Text], page 139.
Sometimes you may need to convert or otherwise prepare a file so that it can be printed on your
particular printer, since not all print hardware can print the same kinds of file formats. Recipes in this
chapter show how to do this, such as how to convert PostScript files so that they will print properly on a
non-PostScript printer (see Section 25.3 [Preparing Files for Printing], page 240).
This chapter also shows how to format PostScript files for printing. To convert plain text to PostScript
and enhance it for printing, by adding fonts, graphic headers, and the like, see Section 15.2 [Converting
Plain Text for Output], page 159.
And this chapter isn’t in the files section, because you can print things that aren’t in a file—for
example, you can pipe the output of another tool or series of tools to lpr, and it will spool that command
output to the printer. This usage is actually very common.
NOTE: When a printer is properly configured on Linux, it is a pleasure to use, but a misconfigured
printer can lead to all kinds of trouble—including the dreaded “staircase effect,” where a text file prints
with each subsequent line of output offset to the right by the length of the previous line.
If print services haven’t been configured yet on your system, I strongly recommend that the
‘magicfilter’ package be installed; it includes filters for the automatic detection of file types—when
you print a file, it automatically converts it to the proper format for your printer.
Comprehensive details on the setup of printer resources can be found in both the Printing HOWTO
and the Printing Usage HOWTO (see Section 2.8.6 [Reading System Documentation and Help Files],
page 31).
$ lpq RET
lp is ready and printing
Rank Owner Job Files Total Size
active groucho 83 cigar.ps 1739030 bytes
1st harpo 84 harp.ps 499 bytes
2nd chico 85 love.ps 45576 bytes
ª$
©
In this example, there are three jobs queued for the default printer—one by user groucho, for the
file ‘cigar.ps’, one by user harpo, for the file ‘harp.ps’, and one by user chico, who has printed
a file called ‘love.ps’.
The job by user groucho is the active job ; this is the job that is currently printing on the printer.
The other jobs must wait until this file is finished printing, and then they print in rank order.
As with lpr, you can specify the name of a printer as an argument to the ‘-P’ option.
¯ To view the spool queue for the printer called bossomatic, type:
$ lpq -P bossomatic RET
To only list the jobs for a particular user, give the name of the user as an argument.
¯ To list the print jobs for user harpo, type:
$ lpq harpo RET
NOTE: When there are no print jobs, lpq outputs the text ‘no entries’.
25.1.4 Cancelling a Print Job
To cancel a print job and remove it from the spool queue, use lprm, the “line printer remove” tool. Give
as an argument the number of the print job to remove.
¯ To cancel print job 83, type:
$ lprm 83 RET
To cancel all of your print jobs in the spool queue, use a hyphen instead of the number of a print job.
¯ To cancel all of your print jobs, type:
$ lprm - RET
NOTE: If you try to cancel an active job—one that has already been spooled to the printer—don’t be
alarmed if some pages still print; the printer probably has some of the job in its internal print buffer. To
stop the printing in a case like this, take the printer offline, reset it, and then put it back online again
(usually, the printer will have buttons for these commands on its front control panel).
If you don’t have a PostScript printer, you can use Ghostscript, gs, to convert PostScript to an output
format that your printer understands.
Use the ‘-?’ option to list the printers that the version of gs installed on your system can write output
for.
¯
« ¨
To list the available printer formats, type:
$ gs -? RET
GNU Ghostscript 5.10 (1998-12-17)
...more output messages...
Input formats: PostScript PostScriptLevel1 PostScriptLevel2 PDF
Available devices:
x11 x11alpha x11cmyk x11gray2 x11mono lvga256 vgalib
t4693d8 tek4696 appledmp ccr lp2563 lbp8 lips3 m8510
oki182 okiibm la50 la70 la75 la75plus sxlcrt deskjet
djet500 laserjet ljetplus ljet2p ljet3 ljet4 declj250
cdeskjet cdjcolor cdjmono cdj550 cdj500 djet500c
hpdj uniprint epson eps9mid eps9high epsonc lq850
ap3250 ibmpro bj10e bj200 bjc600 bjc800 ljet3d faxg3
faxg32d faxg4 dfaxhigh dfaxlow pcxmono pcxgray pbm
pbmraw pgm pgmraw pgnm pgnmraw pnm pnmraw ppm ppmraw
pkm pkmraw tiffcrle tiffg3 tiffg32d tiffg4 psmono
psgray jpeg
...more output messages...
ª
$
©
A typical gs installation can write to more than 100 different print devices, including HP LaserJet 4
printers (‘ljet4’), HP Color DeskJets (‘cdeskjet’), and Group 4 fax (‘tiffg4’). Newer versions
of gs will have better support for newer printers, so make sure that you have a recent version installed if
you have a new model printer.
gs takes the file to convert as an argument; give the device to write output for as an argument to the
‘-sDEVICE=’ option, and give the name of the file to write to as an argument to the ‘-sOutputFile=’
option.
Two additional options are commonly used: ‘-dSAFER’, which prevents the accidental deleting or
overwriting of files, and ‘-dNOPAUSE’, which turns off the pause between pages.
When the conversion is complete, you will be at the gs prompt; type quit to exit.
¯ To convert the file ‘tiger.ps’ to a format suitable for printing on an HP Color DeskJet 500
printer, type:
$ gs -sDEVICE=cdj500 -sOutputFile=tiger.dj -dSAFER -dNOPAUSE
tiger.ps < /dev/null RET
This command writes the output to a file, ‘tiger.dj’, which you can spool as a print job with lpr
to print.
Debian: ‘tetex-bin’
WWW: http://www.radicaleye.com/dvips/
To convert a file from DVI format to PostScript, use dvips. It takes the file to convert as an argument;
give the name of the PostScript file to write to as an argument to the ‘-o’ option.
¯ To convert the file ‘abstract.dvi’ to PostScript, type:
$ dvips -o abstract.ps abstract.dvi RET
This command reads the DVI file ‘abstract.dvi’ and writes a PostScript version of it to the file
‘abstract.ps’; the original file is not altered.
To write only certain pages of a DVI file to the PostScript output, give the page or pages as arguments
to the ‘-pp’ option.
¯ To output only pages 14 and 36 from file ‘abstract.dvi’ to a PostScript file, ‘abstract.ps’,
type:
$ dvips -pp14,36 -o abstract.ps abstract.dvi RET
¯ To output pages 2 through 100 from file ‘abstract.dvi’ to a PostScript file, ‘abstract.ps’,
type:
$ dvips -pp2-100 -o abstract.ps abstract.dvi RET
¯ To output page 1 and pages 5 through 20 from file ‘abstract.dvi’ to a PostScript file,
‘abstract.ps’, type:
$ dvips -pp1,5-20 -o abstract.ps abstract.dvi RET
To specify an output paper size, give it as an argument to the ‘-t’ option; if you have a PostScript
printer, you can also send the output directly to the printer (see Section 25.2.2 [Printing with Dvips],
page 240).
¯ To output the file ‘abstract.dvi’ as a PostScript file, ‘abstract.ps’, with a paper size of
‘legal’, type:
$ dvips -t legal -o abstract.ps abstract.dvi RET
¯ To print the file ‘abstract.dvi’ to the default printer in landscape mode, type:
$ dvips -t landscape abstract.dvi RET
NOTE: This conversion is not only useful for print preparation. Once the DVI file is converted to
PostScript, you can then convert the PostScript to other formats, such as plain text or PDF—see Sec-
tion 20.3 [Converting PostScript], page 209.
Use the ‘-P’ option with dvips to specify the printer name to write output to—use this option
to make output for non-PostScript printers. For example, to convert TEX and LaTeX files to PDF, use
dvips and give ‘pdf’ as an argument to the ‘-P’ option.
¯ To generate a PDF file from the DVI file ‘abstract.dvi’, type:
$ dvips -Ppdf -o abstract.pdf abstract.dvi RET
This command writes a new file, ‘abstract.pdf’, in PDF format.
There are at least two ways to convert and print a file that’s in Adobe’s Portable Document Format (PDF),
usually marked with a ‘.pdf’ file name extension.
The first way is to view the file in xpdf (the PDF file viewer), and then left-click the printer icon.
This won’t actually send the file to the printer, but it writes a PostScript file in the same directory, with
the same base file name as the PDF file but with a ‘.ps’ extension. You can then print this file with lpr
or convert it to another format (see Section 25.3.1 [Preparing a PostScript File for Printing], page 241).
The second way is to use pdf2ps, part of the ‘gs’ package, to convert the PDF file to PostScript
(then print the PostScript output as described for xpdf above). pdf2ps takes two arguments: the name
of the PDF file to convert, and the name of the PostScript file to write to.
¯ To convert the PDF file ‘pricelist.pdf’, type:
$ pdf2ps pricelist.pdf pricelist.ps RET
This command writes a PostScript file ‘pricelist.ps’ in the current directory.
The mtools package provides a collection of tools to facilitate the manipulation of MS-DOS files.
These tools allow you to use and manipulate MS-DOS disks (usually floppies, but Jaz and Zip drives are
supported, too); they can handle the extensions to the MS-DOS format which are used by the different
Microsoft Windows operating systems, including Windows NT.
The following recipes describe how to use some of the tools in this package to get directory listings of
MS-DOS disks, copy files to and from them, delete files on them, and even format them. They’re similar
in use and syntax to the equivalent MS-DOS commands.
NOTE: If you want to use a floppy disk with your Linux system and don’t need DOS compatibility, don’t
bother using this MS-DOS format—the native Linux format is much more efficient (see Section 24.3.1
[Formatting a Floppy Disk], page 235). If you know how long a DOS format takes, you’ll be amazed at
how much faster the Linux format is, too—it will do it so fast you’ll think it didn’t work!
Apple Macintosh computers use a file system called the “Hierarchical File System,” or HFS. The
hfsutils package contains a set of tools to read and write disks in the HFS format.
The following recipes describe the use of the individual tools in this package.
After you run this command, the other tools in the hfsutils package will work on the Macintosh
disk in the first floppy drive.
In all versions of DOS (and all subsequent versions of Microsoft Windows), text files are normally written
with both a linefeed character and a newline, both “invisible” control characters, to signify the end of
each line. In Linux and other unices, text files have only the newline character.
In either of these operating systems, text files that originated from the other may display irregularly—
in DOS and Windows, the lines of a Linux text file may appear to run together; in Linux, a DOS or
Windows text file may have ‘ˆM’ newline characters at the end of each line.
To convert a text file from DOS to Linux, removing the ‘ˆM’ newline characters in the file, use
‘fromdos’. It converts the file you give as an argument, removing the newline characters from the ends
of all its lines.
To convert a text file from Linux to the convention used by DOS and Windows, use todos. It adds
newline characters to the ends of all lines in the file you give as an argument.
¯ To remove the newline characters from the text file ‘autoexec.bat’, type:
$ fromdos autoexec.bat RET
¯ To add newline characters to all of the text files with a ‘.tex’ extension in the current directory,
type:
$ todos *.tex RET
NOTE: Both commands directly write to the files you specify. To make a backup of the original file, use
the ‘-b’ option; before the conversion, this writes a copy of each specified file with a ‘.bak’ file name
extension.
Use word2x to convert Word 6 files to a format you can read. It can convert files to two different
formats: LaTeX and plain text.
Convert to LaTeX when the layout of the original document, including its formatting and font char-
acteristics, is important. When you just need the complete text of the document, convert it to plain text.
word2x can send its output to the standard output, so the latter conversion is useful for adding to a
pipeline.
Word files usually have a ‘.doc’ or ‘.DOC’ extension, which you don’t have to specify—for exam-
ple, if the Word file you want to convert is called ‘resume.doc’, you can simply give ‘resume’ as
the source file. (But if there exists another file named ‘resume’ in the same directory, this trick won’t
work).
If you don’t specify an output file, word2x writes its output to a file with the same base file name
and an appropriate extension for the output format. This is useful for converting a lot of Word files in the
same directory—specifying a wildcard such as ‘*.doc’ as the input and no output name will convert
them all.
You can also set the maximum line width to be used in the output file; specify the width as an argument
to the ‘-w’ option.
The following recipes describe how to use word2x to convert Word files to LaTeX and plain text
format.
NOTE: While word2x does a pretty good job of conversion, it won’t convert any pictures embedded in
Word documents.
Another way to read Word files is to import them into the AbiWord or StarWriter word processors
(see Section 15.6 [Other Word Processors and Typesetting Systems], page 173).
ª$
©
The default format of the output is to display the day of the week; the month name; the day of the
month; the 24-hour time in hours, minutes, and seconds; the time zone; and the year.
Use the ‘-u’ option to output the current date and time in Greenwich Mean Time (also known as
Coordinated Universal Time, or UTC).
¯
«
To output the current date and time in UTC, type:
¨
$ date -u RET
Fri May 11 15:10:29 UTC 2001
ª$
©
Use the ‘-R’ option to output the date in the format described in RFC822 (see Section 11.4 [Word
Lists and Reference Files], page 130): day of week followed by day of month, month name, year, time,
and time zone in numeric format. This is the date format used in email messages.
¯
«
To output the current date and time in RFC822 format, type:
¨
$ date -R RET
Fri, 11 May 2001 11:10:29 -0400
ª$
©
You can also use the ‘-d’ option to specify the precise fields to output, and the order in which to
output them. One useful example is given next; for more information, see the date man page (see
Section 2.8.4 [Reading a Page from the System Manual], page 28).
To output the number of days into the year for a particular date, use ‘-d’ with ’DD MMM ’ +%j,
where ‘DD’ is the day of month and ‘MMM’ is the name of month.
¯
«
To output the numeric day of the year that 21 June falls on in the current year, type:
¨
$ date -d ’21 Jun’ +%j RET
172
ª$
©
The Linux Cookbook: Tips and Techniques for Everyday Use
This command outputs the number 172, which indicates that 21 June of the current year is the 172nd
day of the current calendar year.
NOTE: To ensure that the time on your system clock remains as accurate as possible, your system
administrator should install the ‘chrony’ package; it periodically adjusts the time on the system clock
according to measurements obtained from other servers on the Internet via “Network Time Protocol.”
Debian: ‘saytime’
WWW: http://www.acme.com/software/saytime/
Use the saytime command to output the current system time in an audible message in a male voice.
You must have a sound card installed on your system, and it must be set up with speakers or some other
output mechanism at an appropriate volume level in order for you to hear it (see Section 21.2 [Adjusting
the Audio Controls], page 213).
NOTE: If you’re feeling adventurous, you can record another voice—like your own—and use that
voice instead of the default voice; the sound files used are Sun ‘.au’ files and are kept in the
‘/usr/share/saytime’ directory.
27.3 Calendars
The following recipes describe a few of the basic tools for displaying calendars in Linux.
The cal tool outputs a calendar to the standard output. By default, it outputs a calendar of the current
month.
To output a calendar for a specific year, give just the year as an option.
ª$ ©
Use the ‘-y’ option to output a calendar for the current year.
¯ So, to print out a calendar for the current year to the default printer, type:
cal -y | lpr RET
To output a calendar for a specific month, give both the numeric month and year as arguments.
ª
$
©
27.3.2 Displaying a Calendar in Emacs
Emacs comes with its own calendar service. The calendar function displays a three-month calendar in
a new buffer—it gives the current, previous, and next months, and it puts point on the current date. To se-
lect the month and year to display, preface the calendar function with the universal-argument
command, C-u.
¯ In Emacs, to display a three-month calendar for the current month and year, type:
$ M-x calendar RET
¯ In Emacs, to display a three-month calendar for August 2010, type:
C-u M-x calendar RET
NOTE: When you display a calendar for a specific month and year, Emacs fills in the current year in the
minibuffer; in the example above, the current year was 2001, and BKSP was typed twice to erase the last
two digits, which were replaced with ‘10’ to make it the year 2010.
The calendar tool is a reminder service that you can use to manage your appointments. It reads a
calendar file, which is a text file in the current directory containing a list of appointments and reminders;
then it outputs those entries from the file that have today or tomorrow’s date. (On a Friday, it outputs
entries for that weekend and for the following Monday.)
For example, if today is Friday, June 16, and you run calendar in the same directory as your
« ¨
calendar file, typical output might look like this:
$ calendar RET
6/16 Finish draft of book
Party at Jack’s
Fri Lunch with Kim and Jo, 12:30
Mon Book manuscript due
ª$
©
The calendar tool reportedly first appeared in Version 7 of AT&T UNIX, and was rewritten
early on for the BSD family of Unix. While the BSD derivate is available for Debian as part of the
bsdmainutils package, this tool isn’t yet standard on all Linux distributions.
The following are recipes for writing your calendar files, including other calendar files in your own
calendar file, and for automating the delivery of your reminders.
NOTE: Emacs has its own equivalent to this tool, which it calls the “Diary.” See Info file
‘emacs-e20.info’, node ‘Diary’ for more information on this feature.
NOTE: The name of the command, crontab, is the same as the file, ‘crontab’.
27.5 Contact Managers
Loosely put, a contact manager is a piece of software that helps you keep track of information about
people you may need to contact in the future. In the past, people often called the physical embodiment of
these things a “rolodex,” which incidentally was a brand name for the Cadillac of such contact managers,
the circular Rolodex file that sat atop the desk of every successful 20th century businessman. I hear that
many people use them even today; the following recipes show how it can be done in Linux with less desk
space and faster search times.
###
###
ª
$
©
This works nicely when the information you need is on the same line as the information you search
for—here, the name Scott is on the same line as the telephone number; however, the output did not show
the warning that appears on the next line in the file. And what about when the term you search for and
the information you need are on adjacent lines?
Use the ‘-C’ option with grep to output several lines of context before and after matched lines.
The Linux Cookbook: Tips and Techniques for Everyday Use
¯
« ¨
To output the several lines around the line matching the text ‘olfe’, type:
ª$ ©
Another way to search such a file is to open it as a buffer in Emacs and use any of the Emacs searches.
The Emacs incremental-search function, C-s, is very useful for such files—even for very large
ones. If you do such a search on a large file, and the first result doesn’t turn up the right record, just
keep typing C-s until the right one appears. If you type the letters to search for in all lowercase, Emacs
matches those letters regardless of case.
¯ To search through the current buffer in Emacs for the first entry containing the text ‘New York’,
regardless of case, type:
C-s new york
¯ To search for the next entry containing the text ‘New York’, regardless of case, type:
C-s
You can repeat the second example as many times as you wish to show all entries in the entire buffer
with the text ‘New York’ in them. Once you reach the end of the buffer, type C-s again to loop around
to the beginning of the buffer and continue the search from there. (The minibuffer will tell you when
you’ve reached the end of the buffer, and will remind you to type this if you want to loop the search.)
NOTE: It’s also useful to peruse and search through these kind of files with less—see Section 14.7
[Searching Text in Less], page 155.
The Insidious Big Brother Database is a contact manager tool for use with Emacs. You can use it
with Emacs email and news readers; it stores contact information in records, and allows you to search
for records that match a regular expression, as well as records whose particular fields match a regular
expression (see Section 14.2 [Regular Expressions—Matching Text Patterns], page 148).
There are several ways to add a record to the database. Use the bbdb-create function to manually
add a record (when you run this command, bbdb prompts you to enter the relevant information for each
field). When in a mail reader inside Emacs, type a colon (‘:’) to display the record for the author of the
current message; if there is none, bbdb asks whether or not one should be created.
¯ To create a new bbdb record from scratch, type:
M-x bbdb-create RET
¯ To add a new bbdb record for the author of the current email message, type:
:
Use the bbdb function to search for records—it takes as an argument the pattern or regexp to search
for.
¯ To output records containing the text ‘scott’ anywhere in the record, type:
M-x bbdb RET scott RET
There are additional functions that let you narrow your search to a particular field: bbdb-name,
bbdb-company , bbdb-net, and bbdb-notes, which respectively search the name, company,
email address, and notes fields.
¯ To output records matching the regexp ‘*\.edu’ in the email address, type:
M-x bbdb-net RET *\.edu RET
«
you’d type:
¨
$ mail joe RET
Subject: Bring files to meeting RET
C-d
Cc: RET
Null message body; hope that’s ok
ª$
©
NOTE: For more about using the mail tool, see Section 30.1 [Sending Mail], page 275.
Use the leave tool to remind yourself when you have to leave. Give as an argument the time when you
have to go, using the format of hhmm, where hh is hours in 24-hour format and mm is minutes.
¯ To remind yourself to leave at 8:05 p.m., type:
$ leave 2005 RET
When you run leave with no arguments, it prompts you to enter a time; if you just type RET then
leave exits without setting the reminder. This method is good for adding leave to scripts or to your
‘.bashrc’, so that you may interactively give a time to leave, if desired, when the script runs (see
Section 3.6.4 [Customizing Future Shells], page 43).
NOTE: leave will output a reminder on the terminal screen five minutes before the given time, one
minute before the time, at the time itself, and then every minute subsequently until the user logs off.
The Linux Cookbook: Tips and Techniques for Everyday Use
The shell command separator; see Section 3.1.4 [Running a List of Commands], page 36.
28 Mathematics
Tools and techniques for dealing with numbers are the subject of this chapter: listing them in sequence or
randomly, calculating arithmetic, and converting between units. Larger applications, such as spreadsheets
and plotting tools, are also mentioned.
To do a quick calculation that requires only addition, subtraction, multiplication, or division, use calc.
It takes as an argument a simple mathematical expression, and it outputs the answer.
Use ‘*’ for a multiplication sign and ‘/’ for division; to output the remainder, use ‘%’. You can use
parenthesis to group expressions—but when you do, be sure to quote them (see Section 3.1.1 [Passing
Special Characters to Commands], page 34).
¯
« ¨
To output the result of 50 times 10, type:
ª $
©
¯ To output the result of 100 times the sum of 4 plus 420, type:
« ¨
$ calc ’100*(4+420)’ RET
42400
ª $
©
¯ To output the remainder of 10 divided by 3, type:
« ¨
$ calc 10%3 RET
1
ª$
©
NOTE: This tool is useful for quickly computing a simple arithmetic equation, but it has several draw-
backs: it only outputs whole integers, its operators are limited, and complex expressions must be quoted.
For doing anything more than the simplest operations, see the next recipe, which describes bc.
Debian: ‘bc’
WWW: ftp://src.doc.ic.ac.uk:/pub/gnu/bc-1.05a.tar.gz
When you have a lot of calculations to make, or when you must compute numbers with decimals, use
bc, a calculation language that supports arbitrary precision numbers. Type bc to perform arithmetic
operations interactively, just like you would with a calculator.
Type each statement to evaluate on a line by itself, typing RET at the end the statement; the evaluation
of what you type is output on the following line. Each line you type will be evaluated by bc as an
arithmetic expression. To exit, type quit on a line by itself.
¯
« ¨
To multiply 42 and 17, type:
$ bc RET
bc 1.05
Copyright 1991, 1992, 1993, 1994, 1997, 1998 Free Software
Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type ‘warranty’.
42 * 17 RET
714
quit RET
ª
$
©
In this example, bc output its version number and warranty information when it started; then, the
statement 42 * 17 was typed by the user, bc output the result (‘714’), and then the user typed quit to
exit bc.
By default, digits to the right of the decimal point are truncated from the output—so dividing 10 by
3 would output ‘3’ as a result, and outputting the remainder from this operation by typing 10%3 would
output a ‘1’. However, bc is an arbitrary precision calculator, and you can give the number of digits to
use after the decimal point by specifying the value of the scale variable; its default value is 0.
¯ To use bc to compute the result of 10 divided by 3, using 20 digits after the decimal point, type:
« ¨
$ bc RET
bc 1.05
Copyright 1991, 1992, 1993, 1994, 1997, 1998 Free Software
Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type ‘warranty’.
scale=20 RET
10 / 3 RET
3.33333333333333333333
quit RET
ª
$
©
The following table describes the symbols you can use to specify mathematical operations.
S YMBOL O PERATION
expression + expression Add: output the sum of the two expressions.
expression - expression Subtract: output the difference of the two expressions.
expression * expression Multiply: output the product of the two expressions.
expression / expression Divide: output the quotient of the two expressions.
expression % expression Remainder: output the remainder resulting by dividing the two expres-
sions.
expression ˆ expression Power: raise the first expression to the power of the second expression.
(expressions ) Group an expression or expressions together, altering the standard
precedence of performing operations.
sqrt(expression ) Output the square root of expression.
To output a random number, use random. Give as an argument an integer denoting the range of numbers
to be output; random then outputs a random number from 0 to the number you give, minus one.
¯ To output a random number from 0 to 9, type:
$ random 10 RET
¯ To concatenate all the files in the current directory, whose names are numbers from 25 through 75,
into a new file called ‘selected-mail’, type:
$ cat ‘seq -s " " 25 75‘ > selected-mail RET
ª$
©
NOTE: If no number is given, factor reads numbers from standard input; numbers should be separated
by space, tab, or newline characters.
Use the units tool to convert units of measurement between scales. Give two quoted arguments: the
number and name of the units you have, and the name of the units to convert to. It outputs two values: the
number of the second units you have, and how many of the second kind of unit can make up the quantity
of the first that you’ve specified.
¯
«
To output the number of ounces in 50 grams, type:
¨
$ units ’50 grams’ ’ounces’ RET
* 1.7636981
/ 0.56699046
ª$
©
In this example, the output indicates that there are about 1.7636981 ounces in 50 grams, and that
conversely, one ounce is about 0.56699046 times 50 grams.
The units tool understands a great many different kinds of units—from Celsius and Fahrenheit to
pounds, hectares, the speed of light, and a “baker’s dozen.” All understood units are kept in a text file
database; use the ‘-V’ option to output the location of this database on your system, which you can then
peruse or search through to see the units your version supports.
¯
«
To determine the location of the units database, type:
¨
$ units -V RET
units version 1.55 with readline, units database in
/usr/share/misc/units.dat
ª$
©
In this example, the units database is located in the file ‘/usr/share/misc/units.dat’,
which is the file to peruse to list all of the units data.
Debian: ‘bsdgames’
Use number to convert Arabic numerals to English text. Give a numeral as an argument; with no
argument, number reads a numeral from the standard input.
¯ To output the English text equivalent of 100,000, type:
$ number 100000 RET
There are several ways to connect a Linux box to the Internet. Digital Subscriber Line (DSL) service,
cable modems, and dial-up connections with ISDN or analog modems are currently the most popular
methods. Each of these services have their own hardware and software requirements.
For up-to-date, detailed instructions for using these services on Linux-based systems, the relevant
HOWTOs published by the Linux Documentation Project (http://www.linuxdoc.org/) remain
the definitive guides (see Section 2.8.6 [Reading System Documentation and Help Files], page 31):
¯ ISP Hookup HOWTO, by Egil Kvaleberg
http://www.linuxdoc.org/HOWTO/ISP-Hookup/
¯ DSL HOWTO for Linux, by David Fannin
http://www.linuxdoc.org/HOWTO/DSL-HOWTO/
¯ Cable Modem Providers HOWTO, by Vladimir Vuksan
http://www.linuxdoc.org/HOWTO/Cable-Modem/
The following recipes show how to set up and use a PPP (“Point-to-Point Protocol”) dial-up connec-
tion, long the de facto means of connecting a computer to the Internet over a dial-up line.
In this example, after eight lines of modem initialization strings, the modem is instructed to dial the
ISP dial-up number, ‘5551010’. Some systems need one or two commas after the number to signify
pauses for the modem; only do this if you can’t get a good connection with just the telephone number in
this space.
Next is the “host” line: this is an optional line used by some ISPs whose connection line contains a
choice of services from which you must make a selection before entering your username and password
(some ISPs offer SLIP and shell access along with the standard PPP, for example); customize this and
the following lines as instructed by your ISP.
Finally, the username ‘smith’ is given, and then the password of ‘secret’. The password appears
between two ‘\q’ strings, which—for security purposes—instruct ppp to display the question mark
(‘?’) characters instead of the actual password in system log files or other places where an intruder might
see it.
Next, edit the file ‘/etc/ppp/peers/provider’ so that it contains these lines:
connect "/usr/sbin/chat -v -f /etc/chatscripts/provider"
defaultroute /dev/modem 115200 persist
The last line in this file should include the device name of the modem you are using and the maximum
connect speed to try; the preceding example uses ‘/dev/modem’ as the device name of the modem, and
115,200 bps as the maximum connect speed, which is a good value for a typical 56K modem (a rule
of thumb is to use the highest connect speed your modem supports; you can always go lower when a
connection is made, but you can never raise the speed above what is given here).
Finally, edit the file ‘/etc/resolv.conf’ so that it contains the following, using the two name-
server IP addresses given to you by your ISP:
search .
nameserver nameserver address 1
nameserver nameserver address 2
For the two nameserver address values, use the IP address of the nameserver machines, as given to
you by your ISP. The second is optional—most ISPs have more than one designated nameserver as a
backup in the event that the first system becomes unavailable.
Make sure that your user account has membership to the dialout group; otherwise, you’ll have to
have the superuser account start and stop PPP, which is not recommended (see Section A.3.2 [Letting
Users Access Hardware Peripherals], page 318).
Once you’ve done these things, you should be able to start and stop PPP connections to the Internet.
Complete documentation for setting up PPP is in the ‘/usr/share/doc/ppp’ directory.
29.2 Faxing
Debian: ‘efax’
WWW: http://casas.ee.ubc.ca/efax/
If you have a Class 1 or 2 fax modem, you can send and receive fax (“facsimile”) messages with your
Linux system. The following subsections show how to do this with the efax package, which is designed
for single user systems or relatively simple fax configurations (more complicated tools for faxing exist,
but they are beyond the scope of this book).
To set up efax for faxing, edit the file ‘/etc/efax.rc’ (you must be root to do this). The
important things to specify in this file are the value for ‘DEV’, which is the device name in ‘/dev’
of the fax or modem device (this should almost always be ‘modem’), and the values for ‘FROM’ and
‘NAME’—the fax number and organization name to appear on outgoing faxes.
NOTE: Unless you have membership to the dialout group, you must ask your system administra-
tor for access to the modem hardware before you can use it (see Section A.3.2 [Letting Users Access
Hardware Peripherals], page 318).
More information on faxing is contained in the Fax Server mini-HOWTO (see Section 2.8.6 [Reading
System Documentation and Help Files], page 31).
Another way to do this is to make a text file containing the list of files to fax, one file name per
line, in the order you want them sent. If the files you want to send are not in the current directory, be
sure to write the file names with path names relative to the current directory—so for example, if you
want to send the file ‘header.fax’, which is in your home directory, and the current directory is
‘˜/documents/faxes’, the file should be specified as ‘˜/header.fax’.
¯ To fax all of the files listed in the file ‘fax.list’ to the number ‘555-9099’, dialing ‘9’ first to
obtain an outside line, and using DTMF tone dialing, type:
$ efax -d /dev/modem -t T9,555-9099 $(cat fax.list) RET
NOTE: efax doesn’t delete the files it faxes.
The command described in the previous recipe can only receive one fax; once the fax is received, efax
exits. To set up your system so that you automatically receive all incoming fax messages continually,
until you interrupt it, use ‘faxon’, part of the tinyutils package. It starts efax for receiving an
incoming fax, as explained previously, but after a fax is received, it starts efax again and continues until
you interrupt it.
¯
« ¨
To automatically receive any incoming fax messages, type:
$ faxon RET
efax: Wed Feb 24 08:38:52 1999 efax v 0.8a (Debian release 08a-
6)
Copyright 1996 Ed Casas
efax: 38:52 opened /dev/modem
This command converts a copy of the file ‘chart.pbm’ to the ‘tiffg3’ fax format, writing it to a
file called ‘chart.fax’. The original PBM file is not altered.
To convert a PostScript file to fax format, use gs and specify tiffg3 as the output device to write
to—see Section 25.3.1 [Preparing a PostScript File for Printing], page 241.
¯ To convert the PostScript file ‘resume.ps’ to fax format, type:
$ gs -q -sDEVICE=tiffg3 -dSAFER -dNOPAUSE
-sOutputFile=resume.fax resume.ps < /dev/null RET
This command (typed all on one line) writes a copy of the file ‘resume.ps’ to the file
‘resume.fax’ in ‘tiffg3’ format, which you can then send as a fax. The original PostScript file is
not altered.
To convert a received fax file to a PostScript file that you can then preview (see Section 17.1.2 [Pre-
viewing a PostScript File], page 183) or print (see Section 25.1.1 [Sending a Print Job to the Printer],
page 237), use the ‘-o ps’ option.
¯ To convert ‘19990325.001’, a received fax file, to a PostScript file, type:
$ efix -o ps 19990325.001 > received.ps RET
This command converts the fax file into a PostScript file called ‘received.ps’.
ª ©
The bottom line contains a status bar showing a message describing how to get help, the current
modem settings (in this case, 57,600 bps, 8 data bits, no parity, one stop bit), whether or not cursor
keys work (the mysterious ‘NOR’ message), the version of the program (‘1.82’), the kind of terminal
emulation currently set (‘VT102’), and whether or not an online connection is currently established.
To get a help menu, type C-a z; from this menu, you can press P to set the communications param-
eters, T to set the terminal settings, O to configure minicom, or D to enter the dialing directory.
To dial a number from the main screen, type ATDT followed by the number to dial.
¯ To dial the number ‘368-2208’, type:
ATDT3682208 RET
When you type RET, minicom will begin dialing the number; type any key to interrupt the dialing
and hang up the line. Once connected, type C-a h to hang up the line and type C-a x to hang up the
line and exit the program.
NOTE: minicom isn’t really a way to connect your system to the Internet; to do that, you normally
start a PPP connection, as described earlier in this chapter.
Technically, you can use minicom to dial a computer that is connected to the Internet, like a local Free-Net system, but
your access to the net will be restricted to inside this minicom window; with a traditional Internet connection, such as
PPP, your whole system has direct access to the net, including your Web browsers, email software, and other networking
tools.
30 Email
The primary means of sending plain-text messages (or binaries in attachment files) between users across
computer networks and systems on the Internet is called electronic mail, or email (and more often than
not these days, just “mail”).
The number of email applications (called mail user agents, or MUAs) available for Linux is large,
and you could spend endless hours exploring the details of all of them. Instead of guiding you toward
this route, this chapter attempts to do three things: give a brief intro to using the default mail agent; give
an overview of other well-supported mail agents, with pointers on where to go for more info; and show
how you can use other tools on the system to manipulate your email.
The mail tool is the default mail agent on Debian and most other Linux systems. It comes without
many bells and whistles that are standard with most MUAs, and any user who sends and receives email
more than occasionally will certainly want to learn a more advanced system (see Section 30.6 [Picking
the Right Mail Application], page 283).
However, mail is available on almost all Unix-based systems, and it works in a pinch—by learning
to use it you can always send and receive email on any Linux- or Unix-based system you encounter.
NOTE: On some Unix-based systems, the name of the tool is mailx instead of mail.
The text you type on the ‘Subject:’ line is displayed as the subject of your email message, and
the lines of text you type after that is the body text of the message. Type C-d on a line alone to end the
message. Then, mail prompts for ‘Cc:’ addresses; a “carbon copy” of the email message is sent to any
addresses you give here, if any (just type RET for none, and separate multiple addresses with commas).
When you type, mail just reads the standard input like any other command-line tool, so there’s little
direct editing capability in this basic email service—use C-u to erase the current line, and C-c C-c
(that is, C-c pressed twice) to cancel your input and abort the message altogether.
That’s it! No bells, no whistles—but no time-wasting excess, either.
ª
$
©
This command sends an email message to the user mrs on the local system. The email message itself
is empty, but the subject is a short note asking whether user mrs will be attending a party.
NOTE: Besides being good for sending mail to users that you might share your system with, mail is
useful for sending yourself mail, as a way to give yourself a reminder at your terminal (see Section 27.6.1
[Sending Yourself Email Reminders], page 259).
$ mail RET
Mail version 8.1 6/6/93. Type ? for help.
"/var/spool/mail/m": 3 messages 3 new
>N 1 mrs Mon Sep 6 17:29 13/345 "Re: A modest proposal"
N 2 Ray Tue Sep 7 04:20 15/694 "Latest news"
N 3 lisa@example Tue Sep 7 09:35 19/869 "Re: Hello"
ª
&
©
In this example, the user has three messages waiting—one from mrs, one from Ray, and one from
lisa@example.com.
The mail prompt is an ampersand (‘&’) character; from there, you can read, delete, reply to, and
save messages.
The Linux Cookbook: Tips and Techniques for Everyday Use
When you type RET at the ‘&’ prompt, mail outputs the next unread message to the screen. You can
also type a number to output that message.
¯To read the next unread message in mail, type:
& RET
¯To read message number three in mail, type:
& 3 RET
There are two ways to exit mail: type q to exit mail and apply the deletion commands you have
given, if any, to your INBOX; type x to exit mail and revert the state of your INBOX to how it was
before you ran mail.
¯To exit mail and revert your INBOX to its state before you started mail, type:
& x RET
You can view your mail folders in less or edit them in a text editor, although the folder will appear as
one long scroll containing all of the messages the folder contains.
You can also view them in elm (see Section 30.6 [Picking the Right Mail Application], page 283) or
open them with mail, and they will appear in the normal way as your INBOX would appear with these
tools.
To view a mail folder with elm, give the name of the folder as an argument to the ‘-f’ option.
¯ To view the mail folder ‘˜/email/mrs’ in elm, type:
$ elm -f ˜/email/mrs RET
If you save your mail messages in a lot of separate folders, you can view a sorted list of all messages
from all files by using cat in conjunction with elm. Concatenate all the folders into one with cat and
then view that file in elm as you would view any folder.
¯ To view the contents of all of the email folders in your ‘˜/email’ directory, type:
$ cat ˜/email/* > allmessages RET
$ elm -f allmessages RET
These commands write a new file, ‘allmessages’, in the current directory, containing the contents
of all email folders in ‘˜/email’; then, that file is viewed in elm.
NOTE: To view a list showing who all the messages in a folder are from, use frm; see Section 30.3.4
[Seeing Who Your Mail Is From], page 281.
The biff tool notifies you when new mail arrives, by printing the header and first few lines of a mail
message.
To turn biff on, use ‘y’ as an option. To turn biff off, so that you stop being notified when new
mail arrives, use ‘n’ as an option. biff options don’t take a hyphen.
¯ To turn biff on, type:
$ biff y RET
Some people put the above line in their ‘.bashrc’ file so that biff is always set on in all of their
shells (see Section 3.6.1 [Changing the Shell Prompt], page 42).
Typing biff alone with no options will tell you whether biff is set to ‘y’ or ‘n’.
¯ To see what biff is set to, type:
$ biff RET
The Linux Cookbook: Tips and Techniques for Everyday Use
A companion tool, xbiff, works only in the X Window System (you can use the regular biff in
X, too). When you start it, xbiff draws a window containing a mailbox that looks like this:
When you have mail, xbiff rings the system bell, the window icon reverses color, and the mailbox
flag goes up:
NOTE: The original version of biff was named after a dog. In the early 1980s at a UC Berkeley
computer lab, a girl would bring her dog, Biff, with her when she went to use the computers. Biff was
known for barking at the mailman when he came in to deliver the day’s mail. He was also very popular
with all of the BSD UNIX hackers at Berkeley, and when one of them wrote a mail notification tool, he
thought of Biff—hence the name. (Biff, the dog, died in August 1993.)
Use messages to count the number of mail messages in a folder or file. Give the name of a mail folder
as an argument; with no arguments, it counts the mail you have waiting in your INBOX.
¯ To see how many email messages you have waiting, type:
$ messages RET
¯ To count the number of email messages in the mail folder ‘˜/email/saved’, type:
$ messages ˜/email/saved RET
Noah Friedman has an alternate set of “Spam” images you can use, available from
http://www.splode.com/˜friedman/software/packages/index.html.
30.3.4 Seeing Who Your Mail Is From
Debian: ‘elm-me+’
WWW: ftp://ftp.uu.net/networking/mail/elm
Use frm to output a list of sender names and subjects for your mail. Give the name of a mail folder as
an option; with no options, frm reads your INBOX.
¯ To output a list showing sender names and subjects of your incoming mail, type:
$ frm RET
¯ To output a list showing sender names and subjects of the mail in the file ‘˜/email/saved’, type:
$ frm ˜/email/saved RET
NOTE: An alternate tool, from, works in similar fashion, but it does not output subject lines; instead, it
outputs the names of senders and the time that messages were received.
Use vrfy to determine whether or not a given email address works. This is useful when you are unsure
whether or not you have the right email address for someone. If the address works, vrfy outputs a
message indicating that the recipient exists; if the address is not valid, vrfy outputs a message saying
that the user is unknown.
¯ To verify that the email address user@example.edu is valid, type:
$ vrfy user@example.edu RET
Use the ‘-f’ option to specify a text file containing email addresses; vrfy attempts to verify all
email addresses contained in the file.
¯ To verify all of the email addresses contained in the file ‘net-legends-faq’, type:
$ vrfy -f net-legends-faq RET
NOTE: vrfy relies on the remote system to get this information; in these days of the heavily corpo-
ratized Internet, an increasing number of sites no longer supply this kind of information to the general
public. However, it’s still useful enough to be worth mentioning.
MIME (“Multipurpose Internet Mail Extensions”) is an Internet standard for encoding and attaching files
to mail messages. It’s used when sending image, audio, or other non-plain-text data via email.
Normally, you read and send MIME mail with your MUA. The following recipes, which show ways
to send and receive MIME mail on the command line, are useful for when you just use the mail tool to
read and send occasional mail with an attachment, but the built-in methods for manipulating MIME mail
in any reasonable MUA will invariably be easier and more convenient than the techniques described here
(see Section 30.6 [Picking the Right Mail Application], page 283).
The Linux Cookbook: Tips and Techniques for Everyday Use
« ¨
To read a mail attachment, type:
$ mail RET
Mail version 8.1 6/6/93. Type ? for help.
"/var/spool/mail/m": 1 messages 1 new
>N 1 Photo Dept. Mon Feb 12 14:37 231/10980 "New Images"
& w1 image.mail RET
"image.mail" [New file]
& x RET
« ¨
dali@example.org, type:
$ metasend RET
To: dali@example.org RET
Subject: The image you requested RET
CC: RET
Content-type: image/jpeg RET
Name of file containing image/gif data: dream.jpeg RET
Do you want to encode this data for sending through the mail?
1 -- No, it is already in 7 bit ASCII
2 -- Yes, encode in base64 (most efficient)
3 -- Yes, encode in quoted-printable (less efficient, more readable)
4 -- Yes, encode it using uuencode (not standard, being phased out)
2 RET
Do you want to include another file too (y/n) [n] ? n RET
Delivering mail, please wait... Mail delivery apparently succeeded.
ª$
©
The following table lists values to use in the MIME ‘Content-type:’ field for various kinds of
files.
VALUE F ILE T YPE
application/gzip File compressed with gzip.
application/zip File compressed with zip.
application/postscript PostScript file.
image/jpeg JPEG image file.
image/png PNG image file.
audio/basic Audio file.
audio/mpeg3 MP3 audio file.
audio/wav WAV audio file.
A signature file (often called a “dot sig,” and written as ‘.sig’) is a text file containing text that you
want to appear at the end of email messages and other online postings.
Sometimes, people put their name, email address, and a small quote, or a piece of ASCII art (such as
text written in a figlet font—see Section 16.3.1 [Horizonal Text Fonts], page 178); once the World
Wide Web became popular, many people started including the URL of their home page in their ‘.sig’.
The use of signatures goes in and out of vogue with the years; you can decide whether or not you
want to use one, but whatever you do, be sure to keep your ‘.sig’ at most four lines in length—to use
any more is considered very bad form. A first line consisting only of ‘-- ’ is sometimes used; many
applications recognize this text as the beginning of a ‘.sig’ when processing messages.
You create your signature file in a text editor, just like any other text file. Name the file
‘.signature’ or ‘.sig’, and keep it in your home directory.
If you want to use more than one signature, use sigrot to “rotate” your various signatures—every
time you run sigrot, it selects one of the signature files you keep in your ‘.sigrot’ directory and
writes it to ‘.signature’. To change your ‘.signature’ every time you log in, you would run
sigrot in your ‘.bash_login’ file (see Chapter 3 [The Shell], page 33).
gnus The gnus newsreader for Emacs can also be used to read and send
mail. It has many features and should appeal to Emacs lovers—but a
warning: it can be daunting to learn!
Debian: ‘gnus’
WWW: http://www.gnus.org/
mew mew is an Emacs mail and news facility developed in Japan. It shows
promise as a fairly new MUA and has many features for handling mail
in complex ways.
Debian: ‘mew’
WWW: http://www.mew.org/
mh-e MH-E is an Emacs front end to nmh, below. It’s very powerful, yet it
remains easy to use.
Debian: ‘emacsen-common’
WWW: http://www.emacs.org/
mozilla Netscape Inc.’s open source Web browser, mozilla, has its famil-
iar and self-explanatory email interface that works in the X Window
System.
Debian: ‘mozilla’
WWW: http://www.mozilla.org/
mutt The MUA currently in favor among many vi users is mutt; it is one
of the most popular MUAs for Linux.
Debian: ‘mutt’
WWW: http://www.mutt.org/
nmh The Rand “Mail Handling” system, mh, is not one application but a
collection of small tools for manipulating mail folders. It should ap-
peal to those who excel at building complex commands from combina-
tions of simple tools and operators. nmh is the new “Mail Handling”
system, containing rewrites and improved versions of the mh tools.
Most Linux systems will install this over the old mh.
Debian: ‘nmh’
WWW: http://www.mhost.com/nmh/
vm VM (“View Mail”) is a facility for reading and sending mail in Emacs.
Older than gnus and mew, it is very configurable.
Debian: ‘vm’
WWW: http://www.wonderworks.com/vm/
wl Wanderlust is a MUA for Emacs designed to facilitate reading your
mail on multiple computers.
Debian: ‘wl’
WWW: http://www.gohome.org/wl/
31 The World Wide Web
Next to email, the most useful service on the Internet is the World Wide Web (often written “WWW” or
“Web”). It is a giant network of hypertext documents and services, and it keeps growing by the instant—
anyone with an Internet-connected computer can read anything on the Web, and anyone can publish to
the Web. It could well be the world’s largest public repository of information.
This chapter describes tools for accessing and using the Web. It also describes tools for writing text
files in HTML (“HyperText Markup Language”), the native document format of the Web.
Debian: ‘mozilla’
Debian: ‘skipstone’
WWW: http://www.mozilla.org/
WWW: http://galeon.sourceforge.net/
WWW: http://www.muhri.net/skipstone/
When most people think of browsing or surfing the Web, they think of doing it graphically—and the
mental image they conjure is usually that of the famous Netscape Web browser. Most Web sites to-
day make heavy use of graphic images; furthermore, commercial Web sites are usually optimized for
Netscape-compatible browsers—many of them not even accessible with other alternative browsers. That
means you’ll want to use this application for browsing this kind of Web site.
The version of Netscape’s browser which had been released as free, open source software (see Sec-
tion 1.1.3 [What’s Open Source?], page 10) in 1998 to much fanfare is called Mozilla. When first
released, the Mozilla application was a “developer’s only” release, but as of this writing it is finally
reaching a state where it is ready for general use.
Once the Mozilla browser has been installed, run it in X either by typing mozilla in a shell or by
selecting it from a menu in the usual fashion, as dictated by your window manager.
Like most graphical Web browsers, its use is fairly self-explanatory; type a URL in the Location
dialog box to open that URL, and left-click on a link to follow it, replacing the contents of the browser’s
main window with the contents of that link. One nice feature for Emacs fans is that you can use Emacs-
style keystrokes for cursor movement in Mozilla’s dialog boxes (see Section 10.2.2 [Basic Emacs Editing
Keys], page 111).
Netscape’s browsers, from their earliest Navigator release to their later Communicator series, were always referred to by
the company as Mozilla; this was a pun on the name Mosaic, which had been the first popular graphical Web browser in the
early 1990s—Netscape’s goal had been to make a monster Mosaic.
The Linux Cookbook: Tips and Techniques for Everyday Use
Use the browser-history tool to maintain a history log of all the Web sites you visit.
You start it in the background, and each time you visit a URL in a Web browser (as of this writing,
works with the Netscape, Arena, and Amaya browsers), it writes the name and URL to its current history
log, which you can view at any time.
¯ To start browser-history every time you start X, put the following line in your ‘.xsession’
file:
browser-history &
A trimmed-down Mozilla will soon be available for Debian systems.
The browser history logs are kept in a hidden directory called ‘.browser-history’ in your home
directory. The current history log is always called ‘history-log.html’; it’s an HTML file that you
can view in a Web browser.
¯ To view the current history log with lynx, type:
$ lynx ˜/.browser-history/history-log.html RET
Past history logs have the year, month, and week appended to their name, and they are compressed
(see Section 8.5 [Compressed Files], page 92). After uncompressing them, you can view them just as
you would view the current log (if you are viewing them in Mozilla, you don’t even need to uncompress
them—it handles this automagically.)
You can also use zgrep to search through your old browser history logs. The logs keep the URL and
title of each site you visit, so you can search for either—then when someone asks, “Remember that good
article about such-and-such?” you can do a zgrep on the files in your ‘˜/.browser-history’
directory to find it.
¯ To find any URLs from the list of those you visited in the year 2000 whose titles contain the word
‘Confessions’, type:
$ zgrep Confessions ˜/.browser-history/history-log-2000* RET
This command searches all your logs from the year 2000 for the text ‘Confessions’ in it, and
outputs those lines.
NOTE: For more about zgrep, see Section 14.3.1 [Matching Lines in Compressed Files], page 152.
If you just want to view an image file from the Web, you don’t have to use a Web browser at all—instead,
you can use display, giving the URL you want to view as an argument. This is especially nice for
viewing your favorite webcam image, or for viewing images on ftp sites—you don’t have to log in or
type any other commands at all.
¯ To view the image at ftp://garbo.uwasa.fi/garbo-gifs/garbo01.gif, type:
$ display ftp://garbo.uwasa.fi/garbo-gifs/garbo01.gif RET
NOTE: When viewing the image, you can use all of the image manipulation commands that display
supports, including resizing and changing the magnification of the image. For more information about
display, see Section 17.2 [Viewing an Image in X], page 184.
As of this writing, the venerable lynx is still the standard Web browser for use on Debian systems; it
was also one of the first Web browsers available for general use. It can’t display graphics at all, but it’s
a good interface for reading hypertext.
Type lynx to start it—if a “start page” is defined, it will load. The start page is defined in
‘/etc/lynx.cfg’, and can be a URL pointing to a file on the local system or to an address on the
Web; you need superuser privileges to edit this file. On Debian systems, the start page comes defined
as the Debian home page, http://www.debian.org/ (but you can change this, of course; many
experienced users write their own start page, containing links to frequently-visited URLs, and save it as
a local file in their home directory tree).
To open a URL, give the URL as an argument.
¯ To view the URL http://lycaeum.org/, type:
$ lynx http://lycaeum.org/ RET
When in lynx, the following keyboard commands work:
C OMMAND D ESCRIPTION
and Move forward and backward through links in the current document.
or RET Follow the hyperlink currently selected by the cursor.
Go back to the previously displayed URL.
DEL View a history of all URLs visited during this session.
PgDn or SPC Scroll down to the next page in the current document.
PgUp Scroll up to the previous page in the current document.
Like many of my generation, it was through lynx that I had my first view of the Web.
= Display information about the current document (like all pages in
lynx, type to go back to the previous document).
g Go to a URL; lynx will prompt you for the URL to go to. Type to
insert on this line the last URL that was visited; once inserted, you can
edit it.
h Display the lynx help files.
q Quit browsing and exit the program; lynx will ask to verify this
action.
The following are some recipes for using lynx.
NOTE: Emacs users might want to use the ‘-emacskeys’ option when starting lynx; it enables you
to use Emacs-style keystrokes for cursor movement (see Section 10.2.2 [Basic Emacs Editing Keys],
page 111).
It’s often common to combine this with the options for saving to a file, so that you can retrieve an
annotated text copy of a file from a site that normally requires registration.
¯ To save the URL http://www.nytimes.com/archive/ as an annotated text file,
‘mynews’, type (all on one line):
$ lynx -dump -number_links -auth=cypherpunks:cypherpunks
http://www.nytimes.com/archive/ > mynews RET
NOTE: The username and password argument you give on the command line will be recorded in your
shell history log (see Section 3.4 [Command History], page 40), and it will be visible to other users on
the system should they look to see what processes you’re running (see Section 2.7.2 [Listing All of a
User’s Processes], page 25).
« The preceding example opens the Emacs/W3 home page in a buffer of its own: ¨
ª ©
The following table describes some of the various special W3 commands.
C OMMAND D ESCRIPTION
RET Follow the link at point.
SPC Scroll down in the current buffer.
BKSP Scroll up in the current buffer.
M-TAB Insert the URL of the current document into another buffer.
The Linux Cookbook: Tips and Techniques for Everyday Use
M-s Save a document to the local disk (you can choose HTML Source,
Formatted Text, LaTeX Source, or Binary).
C-o Open a URL.
B Move backward in the history stack of visited URLs.
F Move forward in the history stack of visited URLs.
i View information about the document in current buffer (opens in new
buffer called ‘Document Information’).
I View information about the link at point in current buffer (opens in
new buffer called ‘Document Information’).
k Put the URL of the document in the current buffer in the kill ring, and
make it the X selection (useful for copying and pasting the URL into
another buffer or to another application; see Section 10.4 [Selecting
Text], page 115).
K Put the URL of the link at point in the kill ring and make it the X
selection (useful for copying and pasting the URL into another buffer
or to another application; see Section 10.4 [Selecting Text], page 115).
l Move to the last visited buffer.
o Open a local file.
q Quit W3 mode, kill the current buffer, and go to the last visited buffer.
r Reload the current document.
s View HTML source of the document in the current buffer (opens in
new buffer with the URL as its name).
S View HTML source of the link at point in the current buffer (opens in
new buffer with the URL as its name).
v Show the URL of the current document (URL is shown in the minibuf-
fer).
V Show URL of the link under point in the current buffer (URL is shown
in the minibuffer).
NOTE: If you get serious about using Emacs/W3, you’ll almost certainly want to run the XEmacs flavor
of Emacs—as of this writing, GNU Emacs cannot display images.
Use wget, “Web get,” to download files from the World Wide Web. It can retrieve files from URLs that
begin with either ‘http’ or ‘ftp’. It keeps the file’s original timestamp, it’s smaller and faster to use
than a browser, and it shows a visual display of the download progress.
The following subsections contain recipes for using wget to retrieve information from the Web. See
Info file ‘wget.info’, node ‘Examples’, for more examples of things you can do with wget.
NOTE: To retrieve an HTML file from the Web and save it as formatted text, use lynx instead—see
Section 31.3.1 [Perusing Text from the Web], page 289.
31.5.1 Saving a URL to a File
To download a single file from the Web, give the URL of the file as an argument to wget.
¯ For example, to download ftp://ftp.neuron.net/pub/spiral/septembr.mp3 to a
file, type:
$ wget ftp://ftp.neuron.net/pub/spiral/septembr.mp3 RET
This command reads a given URL, writing its contents to a file with the same name as the original,
‘septembr.mp3’, in the current working directory.
If you interrupt a download before it’s finished, the contents of the file you were retrieving will contain
only the portion of the file wget retrieved until it was interrupted. Use wget with the ‘-c’ option to
resume the download from the point it left off.
¯ To resume download of the URL from the previous example, type:
$ wget -c ftp://ftp.neuron.net/pub/spiral/septembr.mp3 RET
NOTE: In order for the ‘-c’ option to have the desired effect, you should run wget from the same
directory as it was run previously, where that partially-retrieved file should still exist.
This command archives all files on the http://dougal.bris.ac.uk/˜mbt/ Web site whose
directory names begin with ‘/˜mbt’.
To only get files in a given directory, use the ‘-r’ and ‘-l1’ options (the ‘-l’ option specifies the
number of levels to descend from the given level). To only download files in a given directory, combine
these options with the ‘--no-parent’ option, which specifies not to ascend to the parent directory.
Use the ‘-A’ option to specify the exact file name extensions to accept—for example, use ‘-A
txt,text,tex’ to only download files whose names end with ‘.txt’, ‘.text’, and ‘.tex’ ex-
tensions. The ‘-R’ option works similarly, but specifies the file extensions to reject and not download.
¯ To download only the files ending in a ‘.gz’ extension and only in the given directory
‘/˜rjh/indiepop-l/download/’ at ‘monash.edu.au’, type:
$ wget -m -r -l1 --no-parent -A.gz
http://monash.edu.au/˜rjh/indiepop-l/download/ RET
Hypertext Markup Language (HTML) is the markup language of the Web; HTML files are just plain text
files written in this markup language. You can write HTML files in any text editor; then, open the file in
a Web browser to see the HTML markup rendered in its resulting hypertext appearance.
Many people swear by Bluefish, a full-featured, user-friendly HTML editor for X.
Emacs (see Section 10.2 [Emacs], page 108) has a major mode to facilitate the editing of HTML files;
to start this mode in a buffer, type:
M-x html-mode RET
The features of HTML mode include the insertion of “skeleton” constructs.
The help text for the HTML mode function includes a very short HTML authoring tutorial—view the
documentation on this function to display the tutorial.
¯ To read a short HTML tutorial in Emacs, type:
C-h f html-mode RET
NOTE: When you’re editing an HTML file in an Emacs buffer, you can open the same file in a Web
browser in another window—Web browsers only read and don’t write the HTML files they open, so you
can view the rendered document in the browser as you create it in Emacs. When you make and save a
change in the Emacs buffer, reload the file in the browser to see your changes take effect immediately.
31.6.1 Adding Parameters to Image Tags
Debian: ‘imgsizer’
WWW: http://www.tuxedo.org/˜esr/software.html#imgsizer
For usability, HTML image source tags should have ‘HEIGHT’ and ‘WIDTH’ parameters, which specify
the dimensions of the image the tag describes. By specifying these parameters in all the image tags on
a page, the text in that page will display in the browser window before the images are loaded. Without
them, the browser must load all images before any of the text on the page is displayed.
Use imgsizer to automatically determine the proper values and insert them into an HTML file.
Give the name of the HTML file to fix as an argument.
¯ To add ‘HEIGHT’ and ‘WIDTH’ parameters to the file ‘index.html’, type:
$ imgsizer index.html RET
There are several ways to convert HTML files to other formats. You can convert the HTML to plain
text for reading, processing, or conversion to still other formats; you can also convert the HTML to
PostScript, which you can view, print, or also convert to other formats, such as PDF.
To simply remove the HTML formatting from text, use unhtml. It reads from the standard input (or
a specified file name), and it writes its output to standard output.
¯ To peruse the file ‘index.html’ with its HTML tags removed, type:
$ unhtml index.html | less RET
¯ To remove the HTML tags from the file ‘index.html’ and write the output to a file called
‘index.txt’, type:
$ unhtml index.html > index.txt RET
When you remove the HTML tags from a file with unhtml, no further formatting is done to the text.
Furthermore, it only works on files, and not on URLs themselves.
Use lynx to save an HTML file or a URL as a formatted text file, so that the resultant text looks like
the original HTML when viewed in lynx. It can also preserve italics and hyperlink information in the
original HTML. See Section 31.3.1 [Perusing Text from the Web], page 289.
One thing you can do with this lynx output is pipe it to tools for spacing text, and then send that to
enscript for setting in a font. This is useful for printing a Web page in typescript “manuscript” form,
with images and graphics removed and text set double-spaced in a Courier font.
¯ To print a copy of the URL http://example.com/essay/ in typescript manuscript form,
type:
$ lynx -dump -underscore -nolist http://example.com/essay/ | pr -
d
| enscript -B RET
NOTE: In some cases, you might want to edit the file before you print it, such as when a Web page
contains text navigation bars or other text that you’d want to remove before you turn it into a manuscript.
In such a case, you’d pipe the lynx output to a file, edit the file, and then use pr on the file and pipe
that output to enscript for printing.
The Linux Cookbook: Tips and Techniques for Everyday Use
Finally, you can use html2ps to convert an HTML file to PostScript; this is useful when you want
to print a Web page with all its graphics and images, or when you want to convert all or part of a Web
site into PDF. Give the URLs or file names of the HTML files to convert as options. Use the ‘-u’ option
to underline the anchor text of hypertext links, and specify a file name to write to as an argument to the
‘-o’ option. The defaults are to not underline links, and to write to the standard output.
¯ To print a PostScript copy of the document at the URL http://example.com/essay/ to the
default printer, type:
$ html2ps http://example.com/essay/ | lpr RET
¯ To write a copy of the document at the URL http://example.com/essay/ to a PostScript
file ‘submission.ps’ with all hypertext links underlined, type:
$ html2ps -u -o submission.ps http://example.com/essay/ RET
Use weblint to validate the basic structure and syntax of an HTML file. Give the name of the file to
be checked as an argument, and weblint outputs any complaints it has with the file to standard output,
such as whether or not IMG elements are missing ALT descriptions, or whether nested elements overlap.
¯ To validate the HTML in the file ‘index.html’, type:
$ weblint index.html RET
/\
WELCOME TO THE... _! !_
_!__ __!_
__ ! !
_! !_ ! ! ! !
! ! /\ ! ! ! !
! ! ! ! ! ! ! !___
! ! ! ! ! ! ! ! !
! !_!_ ! ! ! ! ! !
! ! ! ! ! ! ! ! !
_! ! !_!_ ! ! !_
! ! !_! ! !
! !
! CLEVELAND FREE-NET !
! COMMUNITY COMPUTER SYSTEM !
!____________________________________!
brought to you by
Are you:
1. A registered user
2. A visitor
Login:
In this example, the user connected to the system at kanga.ins.cwru.edu; the bottom Login:
prompt was the prompt of the remote system (if you are ever unsure what system you are on, use
hostname as a shell prompt; see Section 2.4 [Running a Command], page 22).
To disconnect from the system, follow the normal procedures for logging out from the system you
are connected to (for how to do that on a Linux system, see Section 2.2.2 [Logging Out of the System],
page 19).
¯
« ¨
To disconnect from a remote Linux system, type:
$ C-d
Connection closed.
ª$ ©
In the preceding example, the first shell prompt was on the remote system, and the second prompt
was on the local system.
faraway-system$ C-[
telnet> z RET
[2]+ Stopped telnet
ª$
©
¯ To return to the remote system, type:
« ¨
$ fg RET
ªfaraway-system$
©
In the first of the two preceding examples, the escape character C-[ was typed on the remote system,
whose shell prompt in this example is ‘faraway-system$’ (you don’t have to type the escape char-
acter at a shell prompt, though; you can type it regardless of what program you are running or where you
are on the remote system). Then, the ‘z’ command was given to telnet to suspend the telnet con-
nection. In the second example, the suspended telnet connection to the remote system was brought
back into the foreground.
NOTE: You should be aware that it’s possible (though not often desirable) to “nest” multiple layers of
telnet sessions on top of each other by connecting from one system to the next, to the next, and so
on, without disconnecting from the previous system. To avoid this, make sure you know which host
you’re leaving when you’re about to telnet off to another; the hostname tool is useful for this (see
Section 2.2.1 [Logging In to the System], page 18).
On some systems, your system administrator may ask you to install and use kerberos, openssh, or
some other network security tool so that you may connect to a remote system in a more secure manner
than with telnet. These tools encrypt the data that is passed between the local and remote systems dur-
ing your connect session; they’re becoming very popular today among security-conscious administrators.
Should you be asked to use one, follow your administrator’s instructions in installing and configuring it
for your system.
NOTE: In order to be of any use, the services and tools discussed in this chapter require that your system
is online or otherwise connected to a network; see Chapter 29 [Communications], page 269.
ªftp>
©
In this example, the ‘/pub’ directory contained three subdirectories (‘comp’, ‘rec’, and
‘science’) and two files, ‘INDEX.gz’ and ‘ls-lR.gz’; many public systems have files similar
to these in their ‘/pub’ directories—‘INDEX.gz’ is a listing of all files on their ftp site, with
descriptions, and ‘ls-lR.gz’ is the output of the command ls -lR run on the directory tree of their
ftp server.
The following subsections describe how to upload and download files. Use the quit command to
exit ftp and end the connection to the remote system.
ªftp>
©
In this example, the local current directory is now ‘/home/james/demos’.
There are other important commands for downloading files—use ‘i’ to specify that files be transferred
as binary; normally, the transfer is set up for text files. When you want to transfer programs, archives,
compressed files, or any other non-text file, set the transfer type to ‘i’ first.
In recent years, most public systems have added a security measure forbidding the upload by anony-
mous users to anywhere but the ‘/incoming’ or ‘/pub/incoming’ directories.
The mput command works like put but allows you to specify wildcards. By default, mput asks
you, for each file, whether to upload the file or not; to turn off this file prompting, type prompt before
giving the mput command. This command is a toggle—type prompt again to turn file prompting back
on for your session.
« ¨
‘˜/tmp’ directory, type:
ªftp>
©
NOTE: The mget command works like get but allows wildcards; as with mput, you will be prompted
to verify each file unless you use the prompt command first to turn this off.
Usenet is a famous, vast collection of world-around discussion boards called newsgroups, where mes-
sages (called articles ) can be read and publicly responded to. Newsgroups are named and organized by
hierarchy, with each branch delineated by a period (‘.’); for example, the ‘comp.os.linux’ news-
group is part of the ‘comp.os’ branch of the ‘comp’ hierarchy.
The following table lists the “Big Eight” Usenet hierarchies and give examples of some newsgroups
in each one.
U SENET H IERARCHY D ESCRIPTION
comp Computing. news:comp.os.linux.advocacy,
news:comp.text.tex
humanities Humanities. news:humanities.music.composers.wagner
misc Miscellaneous. news:misc.consumers.frugal-living
news Newsgroups relating to Usenet itself.
news.newusers.questions
The Linux Cookbook: Tips and Techniques for Everyday Use
An application that lets you read and post articles to newsgroups is called a newsreader. Here are some
of the best newsreaders available for Linux-based systems.
N EWSREADER D ESCRIPTION
gnus Gnus is a very powerful and feature-full newsreader for use in Emacs. You can
use it to read mail, too.
Debian: ‘gnus’
WWW: http://www.gnus.org/
knews A graphical newsreader for use in X. Its features include the display of article
threads in a graphical tree, and options for those reading news over slow connec-
tions.
Debian: ‘knews’
WWW: http://www.matematik.su.se/˜kjj/
mozilla Historically, commercial Web browsers also had mail and newsreaders built into
them, and that capability remains in the Mozilla browser.
Debian: ‘mozilla’
WWW: http://www.mozilla.org/
nn The motto of nn is “No News is good news, but nn is better”; it’s an older (and
very popular) newsreader that was designed for reading the most news in the
minimal amount of time.
Debian: ‘nn’
WWW: http://www.math.fu-berlin.de/˜guckes/nn/
pan The “Pimp A** Newsreader” is a new-generation graphical newsreader that is
designed for speed. It is meant to be easy for beginners to use, and it works in X
with GNOME installed.
Debian: ‘pan’
WWW: http://www.superpimp.org/
peruser News Peruser is a suite of small tools for use in X that facilitate the reading and
composing of news articles when you’re offline—it downloads batches of news
when your system is online.
Debian: ‘peruser’
WWW: http://www.ibiblio.org/pub/Linux/system/news/readers/
slrn Based on rn, one of the oldest newsreaders, slrn is optimized for use over slow
connections (like home modem dial-ups).
Debian: ‘slrn’
WWW: http://www.slrn.org/
Debian: ‘nn’
WWW: ftp://ftp.uwa.edu.au/pub/nn/beta/
Use nngrep to find newsgroup names that match a pattern. This is useful for finding groups on a
particular topic.
¯ To output a list of all newsgroups that match the pattern ‘society’, type:
$ nngrep society RET
Use the ‘-u’ option to only search through unsubscribed groups. This is useful if you are subscribed
to a number of groups, and you are looking only for groups you aren’t subscribed to yet.
¯ To output a list of all unsubscribed-to newsgroups that match the pattern ‘society’, type:
$ nngrep society RET
In the previous example, if you were already subscribed to the group alt.society.neutopia,
that group will not be displayed; but other groups matching the pattern ‘society’ that you are not
subscribed to would be listed.
The following tools are used to list the activity of other users and systems on the Internet—showing
whether or not they are currently online and perhaps displaying a little more information about them.
Use ping to determine whether a particular system is currently connected to the Internet.
Type ping followed by the name or numeric IP address of the system you want to check; if your
system is online and the system to be checked is also online, ping should continually output lines
telling how long the latency, in milliseconds, is between the two systems. Type C-c to interrupt it and
stop pinging.
ª
$
©
In this example, the host bfi.org was pinged and a total of three pings were sent and received
before the user typed C-c to interrupt it. As long as these ping lines are output, you know that the other
machine is connected to the Internet (or at least to the same network that your localhost is connected to).
You really don’t need to analyze the information on each line of a ping message—the only useful
information is the number at the end of the line, which tells you how many milliseconds it took to go
out to the Internet, touch or “ping” that host, and come back. The quicker the better—pings that
are four or five digits long (or greater) mean a slow connection between the two machines. When you
interrupt the ping, some statistics are output, including the minimum, average, and maximum number
of milliseconds it took to ping the given host. In the example above, the high was 190 and the low was
159.9 milliseconds, with an average of 170.1.
NOTE: If your own system is not online, ping will report that either the network is unreachable or that
the host isn’t found.
ª$
©
In this example, the user bradley on the system at ap.spl.org is not currently logged in, logged
in last on 20 January, and uses the tsch shell.
“I named it after the sound that a sonar makes, inspired by the whole principle of echo-location,” said the original author of
ping, Mike Muss. He died in an automobile accident in November 2000.
NOTE: On Unix-based systems, you can put information in a hidden file in your home directory called
‘.plan’, and that text will be output when someone fingers you. Some people put elaborate informa-
tion in their ‘.plan’ files; in the early 1990s, it was very much in vogue to have long, rambling .plans.
Sometimes, people put information in their ‘.plan’ file for special events—for example, someone who
is having a party next weekend might put directions to their house in their ‘.plan’ file.
ª$
©
32.4.4 Finding the IP Address of a Host Name
When you know the name of a particular host, and you want to find the IP address that corresponds to it,
ping the host in question; this will output the IP address of the host in parenthesis (see Section 32.4.1
[Checking Whether a System is Online], page 305).
You can also use dig, the “domain information groper” tool. Give a hostname as an argument to
output information about that host, including its IP address in a section labelled ‘ANSWER SECTION’.
¯
«
To find the IP address of the host linart.net, type:
¨
$ dig linart.net RET
...output messages...
;; ANSWER SECTION:
linart.net. 1D IN A 64.240.156.195
...output messages...
ª$
©
In this example, dig output the IP address of 64.240.156.195 as the IP address for the host
linart.net.
¯
« ¨
To find the host name that corresponds to the IP address 216.92.9.215, type:
ª
$
©
In this example, dig output that the host name corresponding to the given IP address was
rumored.com.
ª
$
©
The other user can reply to you by running write and giving your username as an argument. Tra-
ditionally, users ended a write message with ‘-o’, which indicated that what they were saying was
“over” and that it was now the other person’s turn to talk. When a user believed that a conversation was
completed, the user would end a line with ‘oo’, meaning that they were “over and out.”
A similar command, wall, writes a text message to all other users on the local system. It takes a text
file as an argument and outputs the contents of that file; with no argument, it outputs what you type until
you type C-d on a line by itself. It precedes the message with the text ‘Broadcast message from
username ’ (where username is your username) followed by the current system time, and it rings the bell
on all terminals it broadcasts to.
¯ To output the contents of ‘/etc/motd’ to all logged-in terminals, type:
$ wall /etc/motd RET
¯ To output the text ‘Who wants to go out for Chinese food?’ to all logged-in terminals,
type:
$ wall RET
Who wants to go out for Chinese food? RET
C-d
You can control write access to your terminal with mesg. It works like biff (see Section 30.3.2
[Setting Notification for New Mail], page 279): with no arguments, it outputs whether or not it is set;
with ‘y’ as an argument, it allows messages to be sent to your terminal; and with ‘n’ as an argument, is
disallows them.
The default for all users is to allow messages to be written to their terminals; antisocial people usually
put the line mesg n in their ‘.bashrc’ file (see Section 3.6.4 [Customizing Future Shells], page 43).
¯ To disallow messages to be written to your terminal, type:
$ mesg n RET
¯
« ¨
To output the current access state of your terminal, type:
$ mesg RET
is n
ª
$
©
In the preceding example above, mesg indicated that messages are currently disallowed to be written
to your terminal.
Use talk to interactively chat in realtime with another user. Give the username (or email address) of
the user you want to chat with as an argument; a message will be sent to that user’s terminal, indicating
that a connection is requested. If that person then runs talk, giving your username as an argument, you
will both be connected in a talk session—the screen will clear and then what you type will appear on
the top of the screen; what the other user types will appear at the bottom of the screen.
¯ To request a chat with the user kat@kent.edu, type:
$ talk kat@kent.edu RET
This command sends a connection request to the user kat@kent.edu. If the user is not logged on
or is refusing messages, talk will output a message indicating such; but if that user is available, talk
will send a message to that user asking to complete the connection, and it will tell you that it is ringing
your party.
The Linux Cookbook: Tips and Techniques for Everyday Use
If that user then types talk stutz@dsl.org (if, in this example, your email address is
«
stutz@dsl.org), then your screen will clear and you will see the following:
¨
ª ©
You can then type, and what you type will appear on both your screen and that user’s screen; that
user, in turn, can also type—even while you are typing—and what that user types appears on the other
«
half of both screens:
¨
ª ©
It is standard practice to indicate that you are done saying something by typing RET RET, thus
making a blank line on your half of the screen. Some users, when they have typed to the bottom of their
half of the screen, sometimes type RET repeatedly to “clear” their half of the screen and bring the cursor
back to the top.
Type C-c to end a talk session.
When you type, both users see the characters appear in realtime; my first demonstration of the inter-
active nature of the Internet, back in 1991, was when I had a live, real-time chat with a user in Australia,
on the other side of the globe—the magic felt that day has never quite left whenever I run this command!
NOTE: A similar command, ytalk, allows you to connect to multiple users, and it contains other
features as well; it is generally considered to be the superior successor of talk, but it is not yet available
or standard on all Unix-based systems.
C LIENT D ESCRIPTION
bitchx BitchX is an IRC client whose features include ANSI color, so it can
display all of the character escape codes that are popularly used on
IRC for special effects. Despite what you might gather from its name,
it doesn’t require X in order to run.
Debian: ‘bitchx’
WWW: http://www.bitchx.org/
epic EPIC is a large, feature-filled IRC client.
Debian: ‘epic’
WWW: http://www.epicsol.org/
irssi A modular IRC client; note that some versions can only be run in X
with GNOME.
Debian: ‘irssi’
WWW: http://irssi.org/
xchat Xchat is a graphical IRC chat client for use in X.
Debian: ‘xchat’
WWW: http://www.xchat.org/
zenirc ZenIRC is a minimalist, no-frills (yet fully extensible) IRC mode for
Emacs.
Debian: ‘zenirc’
WWW:
http://www.splode.com/˜friedman/software/emacs-
lisp/zenirc/
NOTE: If you’ve never used IRC before, you might want to read The IRC Prelude, on the Web at
http://irchelp.org/irchelp/new2irc.html.
In the late 1990s, a company called Mirabilis released a proprietary program for PCs called ICQ (“I Seek
You”), which was used to send text messages to other users in realtime. Since then, many free software
chat tools have been written that use the ICQ protocol.
One nice feature of ICQ is is that you can maintain a “buddy list” of email addresses, and when you
have an ICQ client running, it will tell you whether or not any of your buddies are online. But unlike
talk, you can’t watch the other user type in realtime—messages are displayed in the other user’s ICQ
client only when you send them.
The following table lists some of the free software ICQ clients currently available.
C LIENT D ESCRIPTION
licq Licq is an ICQ client for use in X.
Debian: ‘licq’
WWW: http://www.licq.org/
micq Micq (“Matt’s ICQ clone”) is an easy-to-use ICQ client that can be
used in a shell.
Debian: ‘micq’
WWW: http://phantom.iquest.net/micq/
zicq Zicq is a version of Micq with a modified user interface.
Debian: ‘zicq’
The Linux Cookbook: Tips and Techniques for Everyday Use
Appendix A Administrative Issues
Every Linux system has an administrator—someone who installs the hardware and software, maintains
the system, and generally keeps things running smoothly. A single-user home Linux system, once in-
stalled and running, needs little administration—but the occasional upgrade or maintenance task is nec-
essary.
This appendix exists as a reference for those users who will also be performing the administrative
duties on their system. While a complete administrative guide is out of the scope of this book, the goal of
this appendix is to point the new Linux administrator in the right direction, giving tips on how to choose
the computer you’ll use for Linux, install Debian GNU/Linux on it, and get it ready for use.
Unlike the rest of this book, this chapter contains recipes describing commands to be run by root,
the superuser account.
If you’re new to Linux administration, you may want to consult the help resources listed in Section 1.3
[If You Need More Help], page 14.
In days gone by, Linux enthusiasts had to piece together computer systems from individual components,
since the salesmen at computer stores had never even heard of Linux or the free software movement. But
no more. Today, many dealers sell complete systems with Linux pre-installed, including corporations
like Dell Computers and IBM.
The Duke of URL reviews the latest hardware as it performs with Linux. His periodic “Linux Buyer’s
Guide” feature lists current hardware that works well on a Linux-based system, and it gives sample
configurations (with prices and links to vendors) for putting together a complete system—from low-end
budget system to a blazing, dual-processor rig.
Since Linux runs on many different computers and supports a wide range of hardware, and because
everyone has different needs, I won’t make too many recommendations as to which specific hardware to
buy. (Systems change too fast for such a list to be useful, anyway.)
Before you make a hardware purchase, though, make sure that it’s compatible with Linux—that
bargain video-capture board will be worthless if it has a proprietary interface that only works with a
certain non-free operating system.
To find out whether your hardware will work under Linux, try the following:
¯ Read the Linux Hardware Compatibility HOWTO (see Section 2.8.6 [Reading System Documen-
tation and Help Files], page 31), an up-to-date list of hardware that is compatible with Linux.
¯ Visit the Linux Hardware Database (http://lhd.datapower.com/) and Linux
Hardware.Net (http://www.linuxhardware.net/) sites, which provide reviews and
information about hardware that works with Linux.
¯ Search the Internet—particularly Usenet news and the linux.com site—for the hardware you
intend to buy. Read any trouble reports people may have written about getting it to work with
Linux, so that you won’t be writing the next report about it.
You can get a copy of Debian GNU/Linux on CD-ROM from local or online vendors, or you can down-
load the installation files from the Internet (recommended only if you have a fast Internet connection, of
course).
If you choose to buy a copy of Debian in a local computer store, be sure you get the most recent
version. If a store only carries an older version, the software might not work with your brand-new
hardware! (Visit the Debian Web site to find the number of the latest version.)
If you’d rather buy a copy online, Cheap*Bytes sells affordable Debian
GNU/Linux CD-ROMs. The Debian Project maintains a full list of vendors at
http://www.debian.org/distrib/vendors/.
The precise details of installation are out of the scope of this book, but the Debian installation guide
comes on the CD-ROM. It contains step-by-step instructions and the latest release notes.
This line means that the script is written in the perl language; the text after the ‘#!’ is the full path
name of the perl program, which in this case is ‘/usr/local/bin/perl’.
If you try to execute this script and the system reports an error finding the file, you’ll have to change
that first line to correspond to the location of the perl binary on your system. The which tool will
output this location.
¯ To find out where perl is installed on your system, type:
$ which perl RET
NOTE: By default, the name of the user’s home directory will be the same as the username. So, for
example, the user bucky will have a home directory of ‘/home/bucky’.
ª$
©
To get a list of the times and dates when the system was recently rebooted, give ‘reboot’ as an
argument to last (see Section 2.6.4 [Listing the Last Times a User Logged In], page 24).
¯ To output a list of times when the system was rebooted, type:
$ last reboot RET
NOTE: An operating system capable of running constantly for a long time without crashes or freeze-ups
is a good one, and so having a high uptime value is a matter of pride for many Linux users. It is not
uncommon to hear of systems that have been running for months and sometimes even years non-stop—
one Linux administrator reported on the Internet about one of his work systems, which had been running
continuously without reboot for three years!
Additionally, the following table lists the primary Web sites for some of the most popular Linux
distributions.
W EB S ITE L INUX D ISTRIBUTION
http://debian.org/ Debian GNU/Linux.
The Linux Cookbook: Tips and Techniques for Everyday Use
The Work is copyright the Author. All rights to the Work are reserved by the Author, except as specifi-
cally described below. This License describes the terms and conditions under which the Author permits
you to copy, distribute and modify copies of the Work.
In addition, you may refer to the Work, talk about it, and (as dictated by “fair use”) quote from it, just as
you would any copyrighted material under copyright law.
Your right to operate, perform, read or otherwise interpret and/or execute the Work is unrestricted; how-
ever, you do so at your own risk, because the Work comes WITHOUT ANY WARRANTY—see Section
7 (“NO WARRANTY”) below.
3. COPYING AND DISTRIBUTION.
Permission is granted to distribute, publish or otherwise present verbatim copies of the entire Source
Data of the Work, in any medium, provided that full copyright notice and disclaimer of warranty, where
applicable, is conspicuously published on all copies, and a copy of this License is distributed along with
the Work.
Permission is granted to distribute, publish or otherwise present copies of the Object Form of the Work,
in any medium, under the terms for distribution of Source Data above and also provided that one of the
following additional conditions are met:
(a) The Source Data is included in the same distribution, distributed under the terms of this License; or
(b) A written offer is included with the distribution, valid for at least three years or for as long as the
distribution is in print (whichever is longer), with a publicly-accessible address (such as a URL on the
Internet) where, for a charge not greater than transportation and media costs, anyone may receive a copy
of the Source Data of the Work distributed according to the section above; or
(c) A third party’s written offer for obtaining the Source Data at no cost, as described in paragraph (b)
above, is included with the distribution. This option is valid only if you are a non-commercial party, and
only if you received the Object Form of the Work along with such an offer.
You may copy and distribute the Work either gratis or for a fee, and if desired, you may offer warranty
protection for the Work.
The aggregation of the Work with other works that are not based on the Work—such as but not limited
to inclusion in a publication, broadcast, compilation, or other media—does not bring the other works in
the scope of the License; nor does such aggregation void the terms of the License for the Work.
4. MODIFICATION.
Permission is granted to modify or sample from a copy of the Work, producing a derivative work, and
to distribute the derivative work under the terms described in the section for distribution above, provided
that the following terms are met:
(a) The new, derivative work is published under the terms of this License.
(b) The derivative work is given a new name, so that its name or title cannot be confused with the Work,
or with a version of the Work, in any way.
(c) Appropriate authorship credit is given: for the differences between the Work and the new deriva-
tive work, authorship is attributed to you, while the material sampled or used from the Work remains
attributed to the original Author; appropriate notice must be included with the new work indicating the
nature and the dates of any modifications of the Work made by you.
5. NO RESTRICTIONS.
You may not impose any further restrictions on the Work or any of its derivative works beyond those
restrictions described in this License.
6. ACCEPTANCE.
Copying, distributing or modifying the Work (including but not limited to sampling from the Work in a
new work) indicates acceptance of these terms. If you do not follow the terms of this License, any rights
granted to you by the License are null and void. The copying, distribution or modification of the Work
outside of the terms described in this License is expressly prohibited by law.
If for any reason, conditions are imposed on you that forbid you to fulfill the conditions of this License,
you may not copy, distribute or modify the Work at all.
If any part of this License is found to be in conflict with the law, that part shall be interpreted in its
broadest meaning consistent with the law, and no other parts of the License shall be affected.
7. NO WARRANTY.
THE WORK IS PROVIDED “AS IS,” AND COMES WITH ABSOLUTELY NO WARRANTY, EX-
PRESS OR IMPLIED, TO THE EXTENT PERMITTED BY APPLICABLE LAW, INCLUDING BUT
NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A
PARTICULAR PURPOSE.
8. DISCLAIMER OF LIABILITY.
IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, IN-
DIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUD-
ING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (IN-
CLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
WORK, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
END OF TERMS AND CONDITIONS
By copylefting your work in this manner, you can make it available for the benefit of everyone—
all copies and modifications of your work remain as equally free as the original—while attribution and
artistic integrity is guaranteed.
If you are interested in applying copyleft to your works, you might be interested in the following
sites:
¯ “Copyleft and the Information Renaissance” (http://dsl.org/copyleft/), a general copy-
left primer and collection of resources, written and maintained by the author.
¯ Free Music Philosophy (http://ram.org/ramblings/philosophy/fmp.html), on the
free music movement, by Dr. Ram Samudrala.
¯ “What is Copyleft?” (http://www.gnu.org/copyleft/), an explanation of copyleft as it
applies to computer software programs, by the GNU Project.
Program Index
. cdinfo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
.bash_logout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 cdir . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
.bash_profile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 cdlabelgen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
.bashrc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 cdparanoia . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
cdpause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
cdplay . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
9 cdrecord. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222
9wm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 cdstop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
cdtool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
ce . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
A chcase. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
Abbrev mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112 chgrp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
addgroup. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318 chmod . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77, 78
adduser . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33, 318 chrony . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251
ae . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 ci . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
afterstep . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 clear . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36, 43
alias . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 cmp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
amaya . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296 co . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
amixer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213 col . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
an . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136 combine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195, 196
animate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188 comm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
aplay . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215 consolechars . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
apropos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26, 36, 37, 38 convert . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196, 204
apt-get . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 316 cooledit. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
arena . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296 cp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68, 72
ascii . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104 crontab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256
aumix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217 cse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
aview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188 cutup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
cvs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
B
balsa . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283
D
banner . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157, 178 dadadodo. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
bash . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33, 149 dap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
bbdb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258 date . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251
bc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261 dc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265
biff . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279 dedit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
bitchx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311 del . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
BitchX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311 df . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
bitmap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199 dia . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
browser-history. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286 diction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127, 128
diff . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91, 134
diff3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
C dig . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307
cal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252 display . . . . . . . . . . . . . . . . . . . 184, 187, 194, 272, 273, 288
calc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261, 265 dissociated-press . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
calendar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254, 255, 256 dome . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265
can . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 dpkg . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26, 316
cat . . 72, 101, 103, 116, 133, 139, 145, 151, 157, 178, 201, drgeo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
263, 320 dselect . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 316
cd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62, 63 dtm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
cd-circleprint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173 du. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87, 233
cdda2wav. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221 dvips. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168, 172, 205, 240
cdeject . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221 dynamic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
The Linux Cookbook: Tips and Techniques for Everyday Use
G
Galeon . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285 K
gawk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116 kali . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
gfont . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179 KDE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
gfontview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179 kerberos. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301
ghostview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159, 183, 205 kill . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
gimp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198, 204 knews . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304
GIMP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194 kraut . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
L mtools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245
last . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24, 319 mutt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283
latex. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168, 169, 170, 172 mv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68, 72
leave . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259 mxv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
less . . . 37, 91, 99, 100, 102, 128, 145, 155, 214, 257, 279,
289, 295
licq . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 312 N
linux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
ln . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 nano . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
locate. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 netpbm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
logout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19, 36 nl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
look . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126, 127 nmh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283
lpq . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238 nn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304
lpr . . . . . . 141, 163, 168, 170, 237, 238, 239, 240, 242, 243 nngrep . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305
lprm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239 notlame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229
ls. . . . . . . . . . . . . . . 43, 63, 64, 65, 67, 72, 76, 77, 86, 87, 235 number . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265
lynx . . . . . 73, 115, 128, 153, 169, 276, 288, 289, 290, 292,
295
lyx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
LyX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169, 239
O
oclock. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
openssh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299, 301
M
m4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
magicfilter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237 P
mail . . . . . . . . . . . . . . . . . . . 256, 259, 275, 276, 277, 278, 279
mailx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275 pan . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304
man . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26, 28, 104, 157, 243 passwd. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
maplay . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217 patch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
mc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 pcdtoppm. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
mcopy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245 pdf2ps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242
mdel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245 perl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116, 136, 153
mdir . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245 peruser . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304
members . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 ping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305, 307
mesg . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 308
play . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
messages. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280
playmidi. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216
metamail. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282
metasend. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282 plog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270
mew . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283 poff . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270
mformat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246 pon . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270
mh-e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283 PostScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
micq . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 312 ppmquant. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
minicom . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273 pr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140, 141, 142, 143, 295
miscfiles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130 ps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25, 39
mkdir . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 ps2pdf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172, 209
mkisofs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235 psbook . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
mogrify . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189, 192, 194
psmerge . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208
montage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
psnup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
moonlight . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
more . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 psresize. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208
mount . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235, 236 psselect. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206
mozilla . . . . . . . . . . . . 63, 73, 183, 187, 283, 285, 287, 304 pstoascii . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
mp3asm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217 psutils . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
mpg321 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215, 230 pwd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62, 63
The Linux Cookbook: Tips and Techniques for Everyday Use
R T
random . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263 tac . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
rcs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94 tail . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
talk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309
rdjpgcom. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194
tar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
rec . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216 ted . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
rel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 telnet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299, 300
remembrance-agent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 tex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167, 168, 169, 170
rev . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146 texinfo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
rlog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96 Texinfo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
rm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70, 72, 84 the . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
rmdir . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70 timidity. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216
todos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248
rxvt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
top . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
touch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62, 83, 89
tr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12, 134, 151
S tree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
saytime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252 twm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
scanimage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202, 203
sced . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199 U
script. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 ul . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
sdiff . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 umount . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235, 236
sed . . . . . . . . . . . . . . . . . . . . . . . . . 102, 103, 116, 139, 140, 153 uname . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319
seq . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263 unexpand. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
sgml2html . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172 unhtml . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295
sgml2info . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172 uniq . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121, 134
units . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264
sgml2latex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
uptime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25, 319
sgml2lyx. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
sgml2rtf. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
sgml2txt. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172 V
sgml2xml. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172 vi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107, 114
sgmlcheck . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172 vim . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
SGMLtools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169, 170 vm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283
sh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 vrfy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281
showcfont . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
showpicture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188 W
shutdown . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
w . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
sigrot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283
w3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290
Skipstone . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285 w3m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296
sleep . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260 wall . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 308
slrn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304 wc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12, 87, 133, 134
snd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225 weblint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296
sort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12, 87, 121, 134, 144 wget . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292, 293, 294
sox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226, 228, 230 whatis. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
spell. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121, 124, 127, 325 which . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88, 317
who . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12, 23
split . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
whoami . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23, 27
startx. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 whois . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 308
style . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127, 129, 133 wily . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
suggest . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128 wl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283
sview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 wm2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
wn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125, 126 xli . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
wnb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125 xlsfonts. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
word2x . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248, 249 xmms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
workbone. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223 xmorph . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
workman . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223 xpaint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
write . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 308 xpaste . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
wrjpgcom. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194 xpcd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187, 203
wterm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 xpdf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184, 242
xsetroot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
xterm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49, 54, 177, 240
X xwave . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
X11R6 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 xwd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
xbiff . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279 xwud . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
xcalc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265
xcdroast. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
xchat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311 Y
Xchat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311
ytalk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309
xclock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49, 52
xcolors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
xdm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
xdvi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168, 183
Z
xedit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 zcat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116, 170, 173
xemacs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108, 109 zenirc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311
XEmacs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108, 290 ZenIRC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311
xfd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177 zgrep . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152, 286
xfig . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199 zgv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
xfontsel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51, 176 zicq . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 312
XFree86 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 zless . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99, 170
The Linux Cookbook: Tips and Techniques for Everyday Use
Concept Index
D directories, renaming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
DAP (Digital Audio Processor) . . . . . . . . . . . . . . . . . . . . . . . 230 directory listings, finding files in . . . . . . . . . . . . . . . . . . . . . . . 86
data CDs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236 directory tree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
date, displaying the . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251 directory tree, finding files in a . . . . . . . . . . . . . . . . . . . . . . . . . 81
Davis, John E. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 directory tree, making a . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
Debian . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
directory, changing to the last one you visited . . . . . . . . . . . 63
Debian Free Software Guidelines (DFSG) . . . . . . . . . . . . . . 10
Debian GNU/Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321 directory, finding the largest files in a . . . . . . . . . . . . . . . . . . . 86
Debian package, installing a . . . . . . . . . . . . . . . . . . . . . . . . . . 316 directory, finding the smallest files in a . . . . . . . . . . . . . . . . . 86
Debian package, upgrading a . . . . . . . . . . . . . . . . . . . . . . . . . 316 disk storage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
Debian, getting and installing . . . . . . . . . . . . . . . . . . . . . . . . . 316 disk usage, listing a file’s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
Debian, what version am I running? . . . . . . . . . . . . . . . . . . . 320 disk, listing the free space on a . . . . . . . . . . . . . . . . . . . . . . . . 233
decompressing a file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
diskettes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
DEdit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
disks, floppy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
definitions, of words . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
delay, running a command on a . . . . . . . . . . . . . . . . . . . . . . . 260 displaying a calendar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252
deleting files and directories . . . . . . . . . . . . . . . . . . . . . . . . . . . 70 displaying a calendar in Emacs . . . . . . . . . . . . . . . . . . . . . . . 254
deleting files on a DOS disk . . . . . . . . . . . . . . . . . . . . . . . . . . 245 displaying information about an audio CD . . . . . . . . . . . . . 220
deleting files on a Macintosh disk . . . . . . . . . . . . . . . . . . . . . 247 displaying information about the system . . . . . . . . . . . . . . . 319
deleting mail . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278 displaying the characters in a console font . . . . . . . . . . . . . 177
Dell Computer Corporation . . . . . . . . . . . . . . . . . . . . . . . . . . . 315
displaying the characters in an X font . . . . . . . . . . . . . . . . . 177
dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 316
Design Science License (DSL) . . . . . . . . . . . . . . . . . . . . . . . . 323 displaying the date and time . . . . . . . . . . . . . . . . . . . . . . . . . . 251
desktop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 distribution, defined . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
desktop environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 document processing, with LyX . . . . . . . . . . . . . . . . . . . . . . . 164
desktop, moving around the . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 Document Type Definition (DTD). . . . . . . . . . . . . . . . . . . . . 170
destroying a window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 documentation, system . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
determining file type and format . . . . . . . . . . . . . . . . . . . . . . . 89
domain name, listing the owner of a . . . . . . . . . . . . . . . . . . . 308
determining the ownership of a file . . . . . . . . . . . . . . . . . . . . . 76
determining whether two files differ . . . . . . . . . . . . . . . . . . . . 91 domain record . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 308
DFSG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 DOS disk, copying files to and from a . . . . . . . . . . . . . . . . . 245
dialects, outputting text in . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 DOS disk, deleting files on a . . . . . . . . . . . . . . . . . . . . . . . . . . 245
DICT Development Group . . . . . . . . . . . . . . . . . . . . . . . . . . . 127 DOS disk, formatting a . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246
diction, checking. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128 DOS disk, listing the contents of a . . . . . . . . . . . . . . . . . . . . 245
dictionaries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
DOS disk, using . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245
dictionaries, online . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
dictionary, personal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122 DOS text files, converting . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248
dictionary, searching for words in the. . . . . . . . . . . . . . . . . . 126 dot files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
difference report . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 double-spacing text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
difference report, patching a file with a . . . . . . . . . . . . . . . . . 91 doubled words, checking text for . . . . . . . . . . . . . . . . . . . . . . 128
directories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 downloading a file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303
directories, changing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
drives, letting users mount . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319
directories, copying . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
DSL (Design Science License) . . . . . . . . . . . . . . . . . . . . . . . . 323
directories, finding the largest . . . . . . . . . . . . . . . . . . . . . . . . . . 87
directories, finding the smallest . . . . . . . . . . . . . . . . . . . . . . . . 87 DSL HOWTO for Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269
directories, listing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 DTD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
directories, listing hidden . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 Duggan, Angus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
directories, listing in color . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 Duke of URL, The . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315, 321
directories, listing options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 DVI file, preparing for printing . . . . . . . . . . . . . . . . . . . . . . . 241
directories, listing tree graphs of . . . . . . . . . . . . . . . . . . . . . . . 66
DVI file, previewing a . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
directories, making . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
directories, moving . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 DVI files, printing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240
directories, naming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 DVI pages, extracting to PostScript . . . . . . . . . . . . . . . . . . . 205
directories, removing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70 Dvips, printing with . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240
E extracting DVI pages to PostScript . . . . . . . . . . . . . . . . . . . . 205
echo area . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 extracting files from an archive . . . . . . . . . . . . . . . . . . . . . . . . . 93
echo, adding to a sound file . . . . . . . . . . . . . . . . . . . . . . . . . . . 227 extracting pages from a PostScript file . . . . . . . . . . . . . . . . . 206
editing images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189 extracting PhotoCD images . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
editing images with the GIMP . . . . . . . . . . . . . . . . . . . . . . . . 198
editing sound files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
editing streams of text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
F
editing text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 fancy headers, outputting text with . . . . . . . . . . . . . . . . . . . . 162
edition of the Cookbook, latest . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Fannin, David . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269
editors, text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 FAQs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
effects, sound . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226 fax format, converting to and from . . . . . . . . . . . . . . . . . . . . 273
ejecting an audio CD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221 fax, receiving a . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272
electronic mail . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275 fax, sending a . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271
elements of an SGML document . . . . . . . . . . . . . . . . . . . . . . 171 faxes, receiving automatically. . . . . . . . . . . . . . . . . . . . . . . . . 272
Elements of Style. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128 faxing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271
eliminating extra spaces in text . . . . . . . . . . . . . . . . . . . . . . . 139 features of LyX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
Emacs . . . . . . . . . . . . . . . . . . . . . . . . 33, 107, 108, 143, 283, 294 Festival. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
Emacs diary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254 FILE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
Emacs, basic editing keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111 file archives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
Emacs, browsing the Web in . . . . . . . . . . . . . . . . . . . . . . . . . . 290 file attributes, listing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
Emacs, counting lines per page in . . . . . . . . . . . . . . . . . . . . . 134 file compression. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
Emacs, displaying a calendar in . . . . . . . . . . . . . . . . . . . . . . . 254 file formats, sound . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
Emacs, getting acquainted with . . . . . . . . . . . . . . . . . . . . . . . 109 file modification time, changing . . . . . . . . . . . . . . . . . . . . . . . . 89
Emacs, inserting special characters in . . . . . . . . . . . . . . . . . 113 file names, changing to lowercase . . . . . . . . . . . . . . . . . . . . . . 69
Emacs, listing relevant files in . . . . . . . . . . . . . . . . . . . . . . . . 135 file names, specifying with patterns . . . . . . . . . . . . . . . . . . . . 72
Emacs, making abbreviations in. . . . . . . . . . . . . . . . . . . . . . . 112 file ownership . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
Emacs, making cut-ups in . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137 file permissions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
Emacs, printing in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239 file revisions, checking in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
Emacs, recording and running macros in . . . . . . . . . . . . . . 112 file revisions, checking out . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
Emacs, searching and replacing in . . . . . . . . . . . . . . . . . . . . 155 file, appending text to a . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
Emacs, searching for a phrase in . . . . . . . . . . . . . . . . . . . . . . 154 file, changing the ownership of a . . . . . . . . . . . . . . . . . . . . . . . 76
Emacs, searching for a regexp in . . . . . . . . . . . . . . . . . . . . . . 155 file, changing the permissions of a. . . . . . . . . . . . . . . . . . . . . . 77
Emacs, searching incrementally in . . . . . . . . . . . . . . . . . . . . 154 file, determining the ownership of a . . . . . . . . . . . . . . . . . . . . 76
Emacs, searching text in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154 file, inserting text at the beginning of a . . . . . . . . . . . . . . . . 118
Emacs, spell checking in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124 file, listing disk usage of a . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
email . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275 file, listing the permissions of a . . . . . . . . . . . . . . . . . . . . . . . . 77
email addresses, verifying . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281 file, mailing a . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276
email reminders, sending yourself . . . . . . . . . . . . . . . . . . . . . 259 file, making a private . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
email signature, making an . . . . . . . . . . . . . . . . . . . . . . . . . . . 283 file, making a public . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
empty file, making an . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 file, making an executable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
empty files, finding in a directory tree . . . . . . . . . . . . . . . . . . 82 file, perusing a text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Encapsulated PostScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205 file, redirecting error messages to a . . . . . . . . . . . . . . . . . . . . . 37
encryption, connecting to another system with . . . . . . . . . 301 file, redirecting input to a . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
envelopes, printing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240 file, redirecting output to a . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
EPS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205 file, saving a URL to a. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293
EPS file, previewing a . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183 files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57, 59
errata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 files and directories. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
error messages, redirecting to a file . . . . . . . . . . . . . . . . . . . . . 37 files, archiving . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
etext . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 files, browsing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
event number . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 files, comparing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
event, history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 files, compressing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
exclusions to the Cookbook . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 files, controlling access to . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
execute permission . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 files, converting Microsoft Word . . . . . . . . . . . . . . . . . . . . . . 248
expansions, file name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 files, copying . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
The Linux Cookbook: Tips and Techniques for Everyday Use
3 The Shell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
3.1 Keys for Command Line Editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
3.1.1 Passing Special Characters to Commands . . . . . . . . . . . . . . . . . . 34
3.1.2 Letting the Shell Complete What You Type . . . . . . . . . . . . . . . . 35
3.1.3 Repeating the Last Command You Typed . . . . . . . . . . . . . . . . . . 35
3.1.4 Running a List of Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
3.2 Redirecting Input and Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
3.2.1 Redirecting Input to a File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
3.2.2 Redirecting Output to a File. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
3.2.3 Redirecting Error Messages to a File . . . . . . . . . . . . . . . . . . . . . . 37
3.2.4 Redirecting Output to Another Command’s Input . . . . . . . . . . 37
3.3 Managing Jobs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
3.3.1 Suspending a Job . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
3.3.2 Putting a Job in the Background . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
3.3.3 Putting a Job in the Foreground . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
3.3.4 Listing Your Jobs. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
3.3.5 Stopping a Job . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
3.4 Command History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
3.4.1 Viewing Your Command History . . . . . . . . . . . . . . . . . . . . . . . . . . 40
3.4.2 Specifying a Command from Your History . . . . . . . . . . . . . . . . 41
3.5 Recording a Shell Session . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
3.6 Customizing Your Shell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
3.6.1 Changing the Shell Prompt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
3.6.2 Making a Command Alias . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
3.6.3 Adding to Your Path . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
3.6.4 Customizing Future Shells . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
6 Sharing Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
6.1 Groups and How to Work in Them . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
6.1.1 Listing the Groups a User Belongs To . . . . . . . . . . . . . . . . . . . . . 75
6.1.2 Listing the Members of a Group . . . . . . . . . . . . . . . . . . . . . . . . . . 75
6.2 File Ownership . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
6.2.1 Determining the Ownership of a File . . . . . . . . . . . . . . . . . . . . . . 76
6.2.2 Changing the Ownership of a File . . . . . . . . . . . . . . . . . . . . . . . . . 76
6.3 Controlling Access to Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
6.3.1 Listing the Permissions of a File . . . . . . . . . . . . . . . . . . . . . . . . . . 77
6.3.2 Changing the Permissions of a File . . . . . . . . . . . . . . . . . . . . . . . . 77
6.3.3 Write-Protecting a File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
6.3.4 Making a File Private . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
6.3.5 Making a File Public . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
6.3.6 Making a File Executable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
The Linux Cookbook: Tips and Techniques for Everyday Use
7 Finding Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
7.1 Finding All Files That Match a Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
7.2 Finding Files in a Directory Tree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
7.2.1 Finding Files in a Directory Tree by Name . . . . . . . . . . . . . . . . . 81
7.2.2 Finding Files in a Directory Tree by Size . . . . . . . . . . . . . . . . . . 82
7.2.3 Finding Files in a Directory Tree by Modification Time . . . . 83
7.2.4 Finding Files in a Directory Tree by Owner . . . . . . . . . . . . . . . . 84
7.2.5 Running Commands on the Files You Find . . . . . . . . . . . . . . . . 84
7.2.6 Finding Files by Multiple Criteria . . . . . . . . . . . . . . . . . . . . . . . . . 84
7.3 Finding Files in Directory Listings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
7.3.1 Finding the Largest Files in a Directory. . . . . . . . . . . . . . . . . . . . 86
7.3.2 Finding the Smallest Files in a Directory . . . . . . . . . . . . . . . . . . 86
7.3.3 Finding the Smallest Directories . . . . . . . . . . . . . . . . . . . . . . . . . . 87
7.3.4 Finding the Largest Directories . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
7.3.5 Finding the Number of Files in a Listing . . . . . . . . . . . . . . . . . . . 87
7.4 Finding Where a Command Is Located . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
8 Managing Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
8.1 Determining File Type and Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
8.2 Changing File Modification Time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
8.3 Splitting a File into Smaller Ones . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
8.4 Comparing Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
8.4.1 Determining Whether Two Files Differ . . . . . . . . . . . . . . . . . . . . 91
8.4.2 Finding the Differences between Files . . . . . . . . . . . . . . . . . . . . . 91
8.4.3 Patching a File with a Difference Report . . . . . . . . . . . . . . . . . . . 91
8.5 Compressed Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
8.5.1 Compressing a File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
8.5.2 Decompressing a File. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
8.6 File Archives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
8.6.1 Creating a File Archive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
8.6.2 Listing the Contents of an Archive . . . . . . . . . . . . . . . . . . . . . . . . 93
8.6.3 Extracting Files from an Archive . . . . . . . . . . . . . . . . . . . . . . . . . . 93
8.7 Tracking Revisions to a File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
8.7.1 Checking In a File Revision . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
8.7.2 Checking Out a File Revision . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
8.7.3 Viewing a File’s Revision Log . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
9 Viewing Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
9.1 Perusing Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
9.1.1 Perusing a Text File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
9.1.2 Perusing Multiple Text Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
9.1.3 Commands Available While Perusing Text . . . . . . . . . . . . . . . 100
9.2 Outputting Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
9.2.1 Showing Non-printing Characters . . . . . . . . . . . . . . . . . . . . . . . . 101
9.2.2 Outputting a Beginning Part of a Text . . . . . . . . . . . . . . . . . . . . 101
9.2.3 Outputting an Ending Part of a Text . . . . . . . . . . . . . . . . . . . . . . 102
9.2.4 Outputting a Middle Part of a Text . . . . . . . . . . . . . . . . . . . . . . . 102
9.2.5 Outputting the Text between Strings. . . . . . . . . . . . . . . . . . . . . . 103
9.2.6 Outputting Text in a Dialect . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
9.3 Streaming Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
9.4 Viewing a Character Chart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
10 Text Editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
10.1 Choosing the Perfect Text Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
10.2 Emacs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
10.2.1 Getting Acquainted with Emacs . . . . . . . . . . . . . . . . . . . . . . . . 109
10.2.2 Basic Emacs Editing Keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
10.2.3 Making Abbreviations in Emacs . . . . . . . . . . . . . . . . . . . . . . . . 112
10.2.4 Recording and Running Macros in Emacs . . . . . . . . . . . . . . . 112
10.2.5 Inserting Special Characters in Emacs. . . . . . . . . . . . . . . . . . . 113
10.3 Running a Vi Tutorial . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
10.4 Selecting Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
10.4.1 Cutting Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
10.4.2 Pasting Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
10.5 Editing Streams of Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
10.6 Concatenating Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
10.6.1 Writing Text to Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
10.6.2 Appending Text to a File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
10.6.3 Inserting Text at the Beginning of a File . . . . . . . . . . . . . . . . . 118
10.7 Including Text Files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
16 Fonts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
16.1 X Fonts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
16.1.1 Selecting an X Font Name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
16.1.2 Listing Available X Fonts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
16.1.3 Displaying the Characters in an X Font. . . . . . . . . . . . . . . . . . 177
16.1.4 Resizing the Xterm Font . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
16.2 Console Fonts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
16.2.1 Setting the Console Font . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
16.2.2 Displaying the Characters in a Console Font . . . . . . . . . . . . . 177
16.3 Text Fonts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
16.3.1 Horizontal Text Fonts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
16.3.2 Making a Text Banner . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
16.4 Other Font Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
20 PostScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
20.1 Manipulating PostScript Pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
20.1.1 Extracting DVI Pages to PostScript . . . . . . . . . . . . . . . . . . . . . 205
20.1.2 Extracting Pages from a PostScript File . . . . . . . . . . . . . . . . . 206
20.1.3 Combining PostScript Pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
20.1.4 Arranging PostScript Pages in Signatures . . . . . . . . . . . . . . . 207
20.2 Manipulating PostScript Documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
20.2.1 Resizing a PostScript Document . . . . . . . . . . . . . . . . . . . . . . . . 208
20.2.2 Combining PostScript Documents . . . . . . . . . . . . . . . . . . . . . . 208
20.2.3 Arranging a PostScript Document in a Booklet . . . . . . . . . . 208
20.3 Converting PostScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
20.3.1 Converting PostScript to PDF . . . . . . . . . . . . . . . . . . . . . . . . . . 209
20.3.2 Converting PostScript to Plain Text . . . . . . . . . . . . . . . . . . . . . 209
25 Printing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
25.1 Making and Managing Print Jobs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
25.1.1 Sending a Print Job to the Printer . . . . . . . . . . . . . . . . . . . . . . . 237
25.1.2 Printing Multiple Copies of a Job . . . . . . . . . . . . . . . . . . . . . . . 238
25.1.3 Listing Your Print Jobs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238
25.1.4 Cancelling a Print Job . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
25.2 More Recipes for Printing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
25.2.1 Printing in Emacs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
25.2.2 Printing with Dvips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240
25.2.3 Printing the Contents of an Xterm Window . . . . . . . . . . . . . . 240
25.3 Preparing Files for Printing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240
25.3.1 Preparing a PostScript File for Printing. . . . . . . . . . . . . . . . . . 241
25.3.2 Preparing a DVI File for Printing . . . . . . . . . . . . . . . . . . . . . . . 241
25.3.3 Preparing a PDF File for Printing . . . . . . . . . . . . . . . . . . . . . . . 242
25.3.4 Preparing a Man Page for Printing . . . . . . . . . . . . . . . . . . . . . . 243
28 Mathematics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261
28.1 Calculating Arithmetic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261
28.1.1 Making a Quick Arithmetic Calculation . . . . . . . . . . . . . . . . . 261
28.1.2 Making Many Arithmetic Calculations . . . . . . . . . . . . . . . . . . 261
28.2 Outputting a Random Number. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263
28.3 Listing a Sequence of Numbers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263
28.4 Finding Prime Factors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264
28.5 Converting Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264
28.5.1 Converting an Amount between Units of Measurement . . 264
28.5.2 Converting an Arabic Numeral to English . . . . . . . . . . . . . . . 265
28.6 Other Math Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265
29 Communications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269
29.1 Connecting to the Internet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269
29.1.1 Setting Up PPP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269
29.1.2 Controlling a PPP Connection . . . . . . . . . . . . . . . . . . . . . . . . . . 270
29.2 Faxing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271
29.2.1 Sending a Fax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271
29.2.2 Receiving a Fax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272
29.2.3 Receiving Faxes Automatically . . . . . . . . . . . . . . . . . . . . . . . . . 272
29.2.4 Converting to and from Fax Format . . . . . . . . . . . . . . . . . . . . . 273
29.3 Calling Out on a Modem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273
The Linux Cookbook: Tips and Techniques for Everyday Use
30 Email . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275
30.1 Sending Mail . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275
30.1.1 Mailing a User on the Same System. . . . . . . . . . . . . . . . . . . . . 275
30.1.2 Mailing a File or the Output of a Command . . . . . . . . . . . . . 276
30.1.3 Mailing the Contents of a URL . . . . . . . . . . . . . . . . . . . . . . . . . 276
30.1.4 Special Mail Composition Keystrokes . . . . . . . . . . . . . . . . . . . 276
30.2 Receiving Mail . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277
30.2.1 Deleting Mail . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278
30.2.2 Options Available while Reading Mail . . . . . . . . . . . . . . . . . . 278
30.3 Managing Mail . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279
30.3.1 Viewing a Mail Folder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279
30.3.2 Setting Notification for New Mail . . . . . . . . . . . . . . . . . . . . . . . 279
30.3.3 Counting How Many Messages You Have . . . . . . . . . . . . . . . 280
30.3.4 Seeing Who Your Mail Is From . . . . . . . . . . . . . . . . . . . . . . . . . 281
30.3.5 Verifying an Email Address . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281
30.4 Mail Attachments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281
30.4.1 Reading a Mail Attachment . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282
30.4.2 Sending a Mail Attachment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282
30.5 Making an Email Signature . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283
30.6 Picking the Right Mail Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283