How to Do Spelling Checks in the Linux Terminal

Bg Spell1

Most text editors often come with a spellchecker that can spellcheck your written piece. What if I tell you that Linux also has its very own command-line spellcheck utility to check your writing in the Terminal?

That utility is called aspell and is installed by default on Ubuntu. This tool has numerous switches available to help us truly appreciate its capabilities. Here is how you can make use of aspell to spellcheck your work in the terminal.

Introducing aspell

Let’s work with a file called “README.md” where some words have been spelled incorrectly.

Spell File

We will run it through the spellchecker using the following command. -c switch is used to specify the file to be checked.

aspell -c README.md

This would bring up an interactive window as shown below. In the top pane the file’s content is displayed. aspell has already processed the file for incorrect spellings. Now it will prompt the words one by one along with suggested corrections, and the user can choose the new spelling for it. Here “Attempyting” is the first instance of a spelling error. In the bottom pane there are suggested words to replace the erroneous word. The numerical value near the suggested words needs to be typed for the spellchecker to do its job.

Spell File Chk1

Once “1” has been typed, aspell moves on to the next erroneous word and displays suggestions to correct it.

Spell File Chk2

In this way, all the required corrections could be made. Once all the changes have been made to a file, the interactive spellchecker exits on its own. A backup for this file is created with the extension “.bak” that has the original erroneous content. “README.md” is the corrected file, and “README.md.bak” is the file with spelling errors.

The configuration file is in “/etc/aspell.conf.” The same can be viewed using the following command:

aspell dump config
Spell File Config1

There is information about the dictionary in use, location of word lists to check against, etc.

Spell File Config2

Using another dictionary

Let us consider the file “country.txt” that has two versions of spellings for the word “recognize.” The version with “s” corresponds to British English and the version with “z” corresponds to American English.

The Indian English dictionary is similar to the British English dictionary. Let’s assume we want to perform a spellcheck on this file based on the American English dictionary.

Spell Us File

The following command shows a long list of the available dictionaries.

apsell dump dicts
Spell Dicts

We can specify the dictionary to use in spell checking using -d switch. Let us use the American English dictionary as shown below.

aspell -d en_US -c "country.txt"

This picks up the first instance of “recognise” with “s” as an error and offers a suggestion that replaces “s” with “z.”

Spell Us File Chk1

Once that correction is performed, the third line in the file is identified as an error. It may be corrected.

Spell Us File Chk2

Using accented letters

Some languages incorporate accented letters as in the file “accents-example.txt” shown below.

Spell Accents

Performing a spellcheck on this file using the default dictionary picks up the accented letter as an error.

aspell -c accents-example.txt
Spell Accents Error

The offered suggestions replace the accented letter with a regular one. Instead, we can use a dictionary which supports accented letters to handle such files.

aspell -d en-w_accents -c accents-example.txt

The dictionary specified accepts accented letters, and the file “accents-example.txt” successfully passes the spell check.

Other options

aspell can be used with HTML/XML files and Tex/LaTex files, too, by providing the predefined switches. It can also be configured to handle hyphenated words and ignore letter cases.

The complete list of options and switches available for aspell can be found in the man page and in the Texinfo manual.

Divya Lakshmanan

Divya divides her time between speculating the existence of aliens and writing about her technical findings.

Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox