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. 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: 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. 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. We can specify the dictionary to use in spell checking using -d switch. Let us use the American English dictionary as shown below. 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. 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. 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.