How to spell check in Linux Terminal

Linux also has a command line spell checker utility in Terminal. The utility is called aspell and is installed by default on Ubuntu. This is how you can use aspell to check spelling in a terminal.

Most text editors often come with a spell checker to check the spelling of your text. But did you know that Linux also has a command line spell checker in Terminal?

The utility is called aspell and is installed by default on Ubuntu. This tool has many switches available, making users really appreciate its capabilities. This is how you can use aspell to check spelling in Terminal.

Introduction to aspell

The article works with a file called README.md , in which some words were misspelled.

Picture 1 of How to spell check in Linux TerminalPicture 1 of How to spell check in Linux Terminal File README.md

The example will run it through the spell checker with the following command.-C switch is used to specify the file to check.

 aspell -c README.md 

This command will open an interactive window as below. In the top section, the file content is displayed.aspell found spelling mistakes. Now, it will prompt each error, along with the proposed error correction plan that the user can choose. Here, 'Attempyting' is the first spelling mistake.

The bottom section contains suggested words to replace the wrong word. A numeric value should be entered near the suggested words for the spell checker to do its job.

Picture 2 of How to spell check in Linux TerminalPicture 2 of How to spell check in Linux Terminal The bottom section contains suggested words to replace the wrong word

After typing 1 , aspell will move to the next wrong word and display suggestions for fixing it.

Picture 3 of How to spell check in Linux TerminalPicture 3 of How to spell check in Linux Terminal All necessary edits can be made

In this way, all necessary edits can be made. When all changes have been made to a file, the interactive spell checker will automatically exit. A backup for this file is created with the .bak extension.README.md is the modified file and README.md.bak is a file with typos.

The configuration file is located in /etc/aspell.conf. The same content can be viewed with the following command:

 aspell dump config 
Picture 4 of How to spell check in Linux TerminalPicture 4 of How to spell check in Linux Terminal The configuration file is located in /etc/aspell.conf

The result has information on the dictionary being used, the position of the word list to check, etc.

Picture 5 of How to spell check in Linux TerminalPicture 5 of How to spell check in Linux Terminal The result has information about the dictionary in use

Use another dictionary

Consider the country.txt file that has two spelling versions 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 English English dictionary. Suppose you want to perform a spell check on this file based on the American English dictionary.

Picture 6 of How to spell check in Linux TerminalPicture 6 of How to spell check in Linux Terminal File country.txt

The following command shows a long list of available dictionaries.

 apsell dump dicts 
Picture 7 of How to spell check in Linux TerminalPicture 7 of How to spell check in Linux Terminal Long list of dictionaries available

You can specify dictionaries to use in spell checking, using the -d switch . Use the American English dictionary as below.

 aspell -d en_US -c "country.txt" 

The first error is the word 'recognize' with the letter s and the proposed suggestion is to replace s with z .

Picture 8 of How to spell check in Linux TerminalPicture 8 of How to spell check in Linux Terminal The first error is the word 'recognize'

When the correction is made, the third line in the file is identified as an error and may be corrected.

Picture 9 of How to spell check in Linux TerminalPicture 9 of How to spell check in Linux Terminal The correction is made

Use accented letters

Some languages ​​that combine accented letters as shown in the accent-example.txt file are shown below.

Picture 10 of How to spell check in Linux TerminalPicture 10 of How to spell check in Linux Terminal File accent-example.txt

Performing a spell check on this file with the default dictionary will treat the accented letter as an error.

 aspell -c accents-example.txt 
Picture 11 of How to spell check in Linux TerminalPicture 11 of How to spell check in Linux Terminal The default dictionary will treat the accented letter as an error

Proposals are provided to replace accented letters with regular letters. In this case, you can use a dictionary that supports accented letters to handle those files.

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

The specified dictionary accepts accented letters and the accents-example.txt file successfully passes the spelling test.

Other options

aspell can also be used with HTML / XML files and Tex / LaTex files by providing predefined switches. It can also be configured to handle hyphenated words and skip upper or lowercase letters.

The full list of options and switches available for aspell can be found on the man page and in the Texinfo guide .

3.7 ★ | 13 Vote