Checking your spelling at the command line with Aspell16 May 2017 | by Scott Nesbitt
Proper spelling doesn’t seem to be very important to many people these days. But there are those of us for whom it is. Yes, I’m one of those people. While I’m not a spelling cop, misspelled words stick out when I encounter them.
Any good text editor and, of course, any word processor packs a spelling checker. But if you’re working in plain text, you can go another route to check spelling: the command line. Specifically, with a nifty utility called GNU Aspell (which I’ll be calling Aspell from here on in).
Aspell is fast, easy to use, and flexible. Let’s take a look at how to use it.
First, make sure that you have Aspell installed on your system. It should be standard kit in most Linux distributions. Just open a terminal window, and type which aspell. That command should return something like /usr/bin/aspell. If it returns nothing, then you can install Aspell using your distro’s package manager or download and install it.
So you have a text file that you want to spell check at the command line. Crack open a terminal window and then navigate to the directory containing the text file that you want to spell check. Then, run the following command:
aspell check file.txt
Aspell opens the text file in a two-pane interactive editor, as shown below:
The top pane shows the file, with any errors (or perceived errors) highlighted. The bottom lists the suggested corrections (based on Aspell’s default dictionary) and various commands that you can use.
In the screen capture above, Aspell has flagged the acronym PDF as an error, and suggested several alternatives. I can do the following:
- Press the number beside an alternative on my keyboard to replace the misspelled word with another one.
- Press i to ignore that instance of the perceived error, or press I to ignore all instances of the error.
- Press a to add the word to Aspell’s dictionary.
- Press r or R to replace that instance or all instances of the word with a new word.
Let’s look at the last item in that list a little more closely. Let’s say I use the word archiving a number of times in a file. And, being a consistent person, I misspell the word archving each time I use it. Aspell will point that out to me:
Instead of having to correct the spelling of that word each time, I want to do it in one fell swoop. So I press R. Aspell prompts me for a replacement.
I type the replacement and then press Enter. The deed is done, and Aspell moves to the next mistake.
Using some of Aspell’s options
Like any command line utility, Aspell has a number of options. You probably won’t use many of them, but here are two that I find useful.
First off, –dont-backup. When you finish spell checking a file, Aspell saves a copy of the original with the extension .bak – for example, djvu_utilities.txt.bak. I don’t like backup files littering my directories. By specifying the –dont-backup option, Aspell doesn’t save a copy.
Next, –mode=. Not all of the files that spell check at the command line are straight text. Often, I’ll check LaTeX or HTML files too. And Aspell flags all of the markup as a mistake. So, instead of filling my dictionary with markup, I can specify –mode=tex or –mode=html. If you want a full list of the modes that you can use, type aspell dump modes.
What you’ve just read is far from an exhaustive look at Aspell and its capabilities. If you’re really interested in what it can do, check out the manual.Thoughts? Let's start a conversation on Twitter.
Did you enjoy this post or find it useful? Then please consider supporting this blog with a micropayment via Liberapay. Thanks!