|[<--] [Cover] [Table of Contents] [Concept Index] [Program Index] [-->]|
The tools and resources for writing and editing on Linux-based systems include spell checkers, dictionaries, and reference files. This chapter shows methods for using them.
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',(18) 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 regardless 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!).
If you're unsure whether or not you're using the correct spelling of a
spell to find out.
spell reads from the standard
input and outputs any words not found in the system dictionary -- so if a
word is misspelled, it will be echoed back on the screen after you type
$ spell [RET] occurance [RET] occurance C-d $
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
To output a list of misspelled words in a file, give the name of the
file to check as an argument to
spell. Any misspelled words in
the file are output, each on a line of its own and in the order that
they appear in the file.
$ spell fall-lecture.draft [RET] occurance willl occurance $
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.
$ 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 Redirecting Output to a File).
To output an alphabetical list of the misspelled words, pipe the
sort; then pipe the sorted output to the
filter to remove duplicates from the list (
uniq removes duplicate
adjacent lines from its input, outputting the "unique" lines).
$ spell fall-lecture.draft | sort | uniq [RET]
The stock American English dictionary installed with Linux-based systems includes over 45,000 words. However large that number may seem, a lot of words are invariably left out -- including slang, jargon, and some proper names.
You can view the system dictionary as you would any other text file, but users never edit this file to add words to it.(19) Instead, you add new words to your own personal dictionary, a file in the same format as the system dictionary, but kept in your home directory as the file `~/.ispell_default'.
Users can have their own personal dictionary; the spelling commands discussed in this chapter automatically use your personal dictionary, if you have one, in addition to the system dictionary.
You build your personal dictionary using the i
and u options of
ispell, which insert words into your
personal dictionary. Use these options either with the stand-alone tool
or with the various
ispell Emacs functions (see Interactive Spell Checking and Spell Checking in Emacs).
NOTE: You can also add (or remove) words by manually editing the file with a text editor, but take care so that the list is kept in alphabetical order!
Over time, personal dictionaries begin to look very personal, as a reflection of their owners; Gregory Cosmo Haun made a work of art by photographing the portraits of a dozen users superimposed with listings of their personal dictionaries (accessible online at http://www.reed.edu/~cosmo/art/DictPort.html).
ispell to spell check a file interactively, so that
every time a misspelling is found, you're given a chance to replace it
then and there.
$ ispell fall-lecture.notes [RET]
When you type this,
ispell begins checking the file. It stops at
the first misspelling it finds:
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:
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].
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
session only, type a; from then on during the current session,
this word will be considered correct.
If, however, you want
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
session and in future sessions, this word, regardless of case, will be
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.
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 following table is a reference to the
ispell key commands.
|[SPC]||Accept misspelled word as correct, but only for this particular instance.|
|number||Replace the misspelled word with the suggestion that corresponds to the given number.|
||Display a help screen.|
|| Accept misspelled word as correct for the remainder of this
||Accept misspelled word as correct and add it to your private dictionary with the capitalization as it appears.|
||Look up words in the system dictionary according to a pattern you then give.|
||Quit checking and restore the file to how it was before this session.|
||Replace misspelled word with a word you type.|
||Accept misspelled word as correct and add it to your private dictionary in all lowercase letters.|
||Save the changes thus made, and then stop checking this file.|
Emacs has several useful commands for spell checking. The
functions, as you might guess from their names, use the
command inside Emacs to check portions of the current buffer.
The first command,
ispell-word, checks the spelling of the word
at point; if there is no word at point, it checks the first word to the
left of point. This command has a keyboard shortcut, M-$. The
ispell-region, checks the spelling of all words
in the currently selected region of text. The third command,
ispell-buffer, checks the spelling of the entire buffer.
M-x ispell-word [RET]
M-x ispell-region [RET]
M-x ispell-buffer [RET]
Flyspell mode is another useful Emacs spelling command that, when
set in a buffer, highlights misspelled words. This function is useful
when you are writing a first draft in a buffer, because it lets you
catch misspellings as you type them.
Flyspellmode in a buffer, type:
M-x flyspell-mode [RET]
NOTE: This command is a toggle; run it again to turn it off.
To correct a word in
Flyspell mode, click and release the middle
mouse button on the word to pull up a menu of suggestions; you then use
the mouse to select the replacement word or add it to your personal
If there are words you frequently misspell, you can define abbrevs for them (see Making Abbreviations in Emacs). Then, when you type the misspelled word, Emacs will automatically replace it with the correct spelling.
Finally, if you prefer the sparse, non-interactive interface of
spell, you can use the Emacs interfaces to that command instead:
Spell region, and
Spell buffer. When
any of these commands find a misspelling, they prompt for a replacement
in the minibuffer but do not offer suggestions or provide any of
ispell's other features.
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 arranged in synonym sets. You can search
the database and output the results in text with the
wn tool or
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,
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.
$ wn browse [RET]
The following sections show how to use
wn on the command line.
NOTE: For more information on WordNet, consult the
man page (see Reading a Page from the System Manual).
There are several ways to search for and output words from the system dictionary.
look to output a list of words in the system dictionary that
begin with a given string -- this is useful for finding words that begin
with a particular phrase or prefix. Give the string as an argument; it
is not case sensitive.
$ look homew [RET]
This command outputs words like `homeward' and `homework'.
Since the system dictionary is an ordinary text file, you can also use
grep to search it for words that match a given pattern or regular
expression (see Regular Expressions -- Matching Text Patterns).
$ grep -i dont /usr/dict/words [RET]
$ grep ing^ /usr/dict/words [RET]
$ grep -i '^[aeiou]*$' /usr/dict/words [RET]
To find some words that rhyme with a given word, use
search `/usr/dict/words' for words ending in the same last few
characters as the word they should rhyme with (see Matching Lines Ending with Certain Text).
$ grep 'end$' /usr/dict/words [RET]
Finally, to do a search on the WordNet dictionary, use
one of the `-grep' options. When you give some text to search for
as an argument, this command does the equivalent search as
except only the particular kind of word sense you specify is searched:
`-grepn' searches nouns, `-grepv' searches verbs,
`-grepa' searches adjectives, and `-grepr' searches
adverbs. You can combine options to search multiple word senses.
$ wn homew -grepn [RET]
$ wn homew -grepn -grepa [RET]
To list the definitions of a word, give the word as an argument to
wn, followed by the `-over' option.
$ wn slope -over [RET]
A synonym of a word is a different word with a similar meaning
that can be used in place of the first word in some context. To output
synonyms for a word with
wn, give the word as an argument,
followed by one of the following options: `-synsn' for nouns,
`-synsv' for verbs, `-synsa' for adjectives, and `-sysnr'
$ wn break -synsn [RET]
$ wn break -synsv [RET]
An antonym of a word is a different word that has the opposite
meaning of the first in some context. To output antonyms for a word with
wn, give the word as an argument, followed by one the following
options: `-antsv' for verbs, `-antsa' for adjectives, and
`-antsr' for adverbs.
$ wn sad -antsa [RET]
A hypernym of a word is a related term whose meaning is more general than the given word. (For example, the words `mammal' and `animal' are hypernyms of the word `cat'.)
To output hypernyms for a word with
wn, use one of the following
options: `-hypen' for nouns and `-hypev' for verbs.
$ wn cat -hypen [RET]
Debian `dict' WWW: http://www.dict.org/
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 systems:
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.(20)
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:
previously in this chapter.
diction to check for wordy, trite, clichéd, or misused
phrases in a text. It checks for all the kind of expressions William
Strunk warned us about in his Elements of Style.
According to The UNIX Environment, by Andrew Walker, the
diction tool that came with the old Writer's Workbench just
found the phrases, and a separate command called
would output suggestions. In the GNU version that works for Linux
systems, both functions have been combined in the single
diction, the words or phrases are enclosed in brackets
`[like this]'. If
diction has any suggested replacements,
it gives them preceded by a right arrow, `-> like this'.
When checking more than just a screenful of text, you'll want to pipe
the output to
less so that you can peruse it on the screen
(see Perusing Text), or pipe the output to a file
for later examination.
$ diction dissertation | less [RET]
$ diction dissertation > dissertation.diction [RET]
If you don't specify a file name,
diction reads text from the
standard input until you type C-d on 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
(If you expect there to be a lot of output, add another pipe at the end
less so you can peruse it.)
$ lynx -dump -nolist http://example.org/1.html | diction | less [RET]
One of the things that
diction looks for is doubled words -- words
repeated twice in a row. If it finds such a sequence, it encloses the
second member of the doubled pair in brackets, followed by a right arrow
and the text `Double word', like `this [<i>this -> Double
To check a text file for doubled words only, and not for any of
the other things
diction checks, use
grep to find only
those lines in
diction's output that contain the text
`Double word', if any.
$ diction dissertation | grep 'Double word' [RET]
style command analyzes the writing style of a given text. It
performs a number of readability tests on the text and outputs their
results, and it gives some statistical information about the sentences
of the text. Give as an argument the name of the text file to check.
$ style dissertation [RET]
style reads text from the standard input if
no text is given -- this is useful for the end of a pipeline, or for
checking the writing style of a particular sentence or other text you
The sentence characteristics of the text that
style outputs are
The various readability formulas that
style uses and outputs are
To output just the "difficult" sentences of a text, use
with the `-r' option followed by a number;
style will output
only those sentences whose Automated Readability Index (ARI) is greater
than the number you give.
$ style -r 20 dissertation [RET]
style to output sentences longer than a certain length by
giving the minimum number of words as an argument to the `-l'
$ style -l 14 dissertation [RET]
Debian: `miscfiles' WWW: ftp://ftp.gnu.org/pub/gnu/miscfiles/miscfiles-1.1.tar.gz
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 Perusing Text).
The following table lists the files in `/usr/share/misc' and describes their contents.
||The GNU Manifesto.|
||Collections of common abbreviations used in electronic communication. (This is the place to look to find the secrets of `TTYL' and `LOL'.)|
||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.|
||A chart of the ASCII character set.|
||The traditional stone and flower tokens for each month.|
||The population, political coordinates (nation, region), and geographic coordinates (latitude, longitude) of many major cities.|
||International country and city telephone codes.|
||Two-letter codes for languages, from ISO 639.|
||A chart of the extended ASCII character set, also known as the ISO 8859 ("Latin-1") character set.|
||Description of all the public Project GNU-related mailing lists.|
||North American (+1) telephone area codes.|
||Precedence table for operators in the C language.|
||Postal codes for U.S. and Mexican states and Canadian provinces.|
||The Constitution of the United States of America (no Bill of Rights, though). (On Debian systems, this file is placed in `/usr/share/state'.)|
||The Declaration of Independence of the Thirteen Colonies. (On Debian systems, this file is placed in `/usr/share/state'.)|
||Indexes of Internet standardization Request For Comments (RFC) documents. (On Debian systems, this file is placed in `/usr/share/rfc').|
||U.S. five-digit Zip codes.|
||Internet protocol parameter registry documents, as published by the Internet Assigned Numbers Authority.|
||A collection of important RFCs, stored in `/usr/share/rfc'.|
||The "Jargon file," which is the definitive dictionary of hacker slang.|
||List of computer acronyms.|
miscfilesdistribution 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'.
[<--] [Cover] [Table of Contents] [Concept Index] [Program Index] [-->]