How to Do Spelling Checks in the Linux Terminal

Spread the love

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.

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.

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

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

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

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.

Also read: How to Install a Dictionary for Use in Linux Terminal

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.

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

apsell dump 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.”

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

Using accented letters

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

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

aspell -c accents-example.txt

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.

Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox

Sign up for all newsletters.
By signing up, you agree to our Privacy Policy and European users agree to the data transfer policy. We will not share your data and you can unsubscribe at any time. Subscribe


Divya Lakshmanan

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

Comments are closed