![Bg Spell1](https://www.maketecheasier.com/assets/uploads/2020/02/bg-spell1.jpg)
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](https://www.maketecheasier.com/assets/uploads/2020/02/spell-file.png)
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](https://www.maketecheasier.com/assets/uploads/2020/02/spell-file-chk1.png)
Once “1” has been typed, aspell moves on to the next erroneous word and displays suggestions to correct it.
![Spell File Chk2](https://www.maketecheasier.com/assets/uploads/2020/02/spell-file-chk2.png)
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](https://www.maketecheasier.com/assets/uploads/2020/02/spell-file-config1.png)
There is information about the dictionary in use, location of word lists to check against, etc.
![Spell File Config2](https://www.maketecheasier.com/assets/uploads/2020/02/spell-file-config2.png)
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](https://www.maketecheasier.com/assets/uploads/2020/02/spell-us-file.png)
The following command shows a long list of the available dictionaries.
apsell dump dicts
![Spell Dicts](https://www.maketecheasier.com/assets/uploads/2020/02/spell-dicts.png)
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](https://www.maketecheasier.com/assets/uploads/2020/02/spell-us-file-chk1.png)
Once that correction is performed, the third line in the file is identified as an error. It may be corrected.
![Spell Us File Chk2](https://www.maketecheasier.com/assets/uploads/2020/02/spell-us-file-chk2.png)
Using accented letters
Some languages incorporate accented letters as in the file “accents-example.txt” shown below.
![Spell Accents](https://www.maketecheasier.com/assets/uploads/2020/02/spell-accents.png)
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](https://www.maketecheasier.com/assets/uploads/2020/02/spell-accents-error.png)
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.
Our latest tutorials delivered straight to your inbox