X
Popular Searches

How to Use Aspell to Spell Check Your Text Files at the Linux Command Line

Shutterstock/Gustavo Frazao

Ever wanted to spell check text files directly from the Linux command line? This article will get your setup and started with Aspell, the interactive spell checker. Start spell checking your text files, for free, today!

What Is Aspell?

GNU Aspell is an open source and free spell checker which can be installed easily on your Linux system. You can use it at the command line, and with a few option tweaks one can check text files reliably and quickly. This article was spell checked with Aspell at the command line, as well as spellintian which is another utility you may like to explore.

Installing Aspell

To install Aspell on your Debian/Apt based Linux distribution (Like Ubuntu and Mint), execute the following command in your terminal:

sudo apt install aspell

If the above command does not automatically install aspell-en on your system as well, please add it to the command line.

Installing aspell

To install Aspell on your RedHat/Yum based Linux distribution (Like RHEL, Centos and Fedora), execute the following command in your terminal:

sudo yum install aspell

Let’s spell check!

Let’s create a file with a variety of spelling errors:

File full of spelling mistakes

We can now check this file with Aspell:

aspell --master=en_US --lang=en_US -c test_spelling.txt

The -c option will spell check a single file, and the --master and --lang settings point Aspell to using a single specified directory, or terminate in case this is not possible. Here we use the en_US dictionary to use the US English language.

Another option which I personally use regularly, and it is so new it has not been added to the manual yet, is --mode=markdown, which makes Aspell aware of the fact that one is using markdown based text. This may help with avoiding false positives.

For additional options, language settings, and different modes, you can reference the Aspell manual by using man aspell at the command line. For English language abbreviations like en_US and en_GB, see the installation screenshot above as it highlights the ones installed.

You may also need to install additional packages if you are interested in other languages. For example, aspell-de can be installed for German support, etc.

Output and Performance

I have been using Aspell for quite some time, and have found it to be a highly reliable, fast, low-key, and easy-to-use spell checker. The personal dictionary feature (saved in the .aspell.en.pws file in your home directory, i.e. ~/.aspell.en.pws) works exceedingly well.

Let’s check our file with spelling errors.

Aspell proposed correction #1

I simply press 1 to substitute ‘Thiz’ to the proposed ‘This’.

Aspell proposed correction #2

Slightly trickier, but option 3 is the way to go. A simple 3 keypress and we’re onto the next error found.

Aspell proposed correction #3

Pressing 4 and moving on…

Aspell proposed correction #4

The first option looks right. A simple 1 keypress.

All other words were all 1 keypresses also. And, thanks to Aspell, our file now contains a lie:

Final output file fully corrected by aspell

As all spelling mistakes are fixed!

By pressing a single key per mistake, we were able to fix all errors in this file. We could have also added a word if the dictionary was not aware of it (happens somewhat infrequently) by pressing a, and we can press the r key to type a new word ourselves to replace whatever mistake was found. If Aspell cannot find the new word we just typed, it will re-highlight it and we can correct it, add it, or replace it again.

As you can see, spell checking text based files at the Linux command line is easy and straightforward with the Aspell tool. Enjoy!

Roel Van de Paar Roel Van de Paar
Roel has 25 years experience in IT & business, 9 years of leading teams, and 5 years in hiring & building teams. He worked for companies like Oracle, Volvo, Sun, Percona, Siemens, Karat and now MariaDB in various senior, principal, lead and managerial roles. Read Full Bio »

The above article may contain affiliate links, which help support CloudSavvy IT.