Aspell: Command line spell check - gHacks Tech News

Aspell: Command line spell check

Spell check is a "feature" we all take for granted. No matter where we are typing - in a document, on a blog, in an email...we all know our spell check will be there to take care of us. But what do we do about those files that are not created or edited in tools without spell checkers? I don't know about you, but I create a lot of files in applications that have no spell check. For those files I invoke the power of aspell.

Aspell is an interactive, command-line spell checking tool. It's really easy to use, reliable, and flexible. You can even use aspell to generate word lists for tools like password cracking tools (and we'd only use those types of tools when we have lost our own passwords right!). In this article I will show you how install and use the command line tool aspell.

Installation

In most cases, aspell should be installed on your machine as it is used by a number of applications. In the event it is not, the installation is simple. Naturally, since aspell is a command-line tool, let's install it via the command line. This installation can be done with a single command like so:

sudo apt-get install aspell

The above is for Ubuntu and/or Debian-based distributions. If you are using a Fedora-like distribution (think rpm-based), you could install with the command:

yum install aspell

There may, or may not, be dependencies to install along with aspell which your installer should pick up.

That's it. You should now have a working copy of aspell installed.

Usage

The basic usage of aspell is as such:

aspell [options] <command> file

Figure 1

The above may seem a bit confusing, but remember, since aspell is used by numerous applications, it is a very powerful tool. That power can be simplified very easily. Let's first take a look at how aspell can be used to spell check a file. Say you have a file, my_file.txt, that you need checked. From the command line you could issue:

aspell -c my_file.txt

For example's sake I copied text from a recent article I wrote and named it my_file.txt. When I run aspell against that file it looks like what you see in Figure 1. As you can see, what aspell will do is step through the file, word by word, and check the spelling. When aspell comes across a word it thinks is incorrect you get a list of possible solutions that you can choose from. Choose your solution and aspell will move on to the next word. It's really quite simple.

Use the aspell dictionary

Aspell can be used in many ways. One very interesting way is to take advantage of the included dictionary. Let's say you need to generate an alphabetized word list (I had to do this recently to try to crack a forgotten password for a client - it was completely legit). To do this I took advantage of aspell's dictionary like so:

Download the specific aspell dictionary I needed from here.

Unpack the dictionary with the commands bunzip2 aspell-XXX.tar.bz2 and tar xvf aspell-XXX.tar (Where XXX is the release number).

  1. Change into the aspell-XXX directory.
  2. Expand the .wl files with the command preunzip *wl
  3. Merge the dictionary files into one file with the command sort –unique –ignore-case *wl > wordlist.txt.
  4. Convert the list to UTF-8 with the command iconv -f ISO8859-1 -t UTF-8 list.txt >utf_wordlist.txt.

Now you will have a word list, containing a single word per line, thanks to the aspell dictionaries. Pretty cool.

Final thoughts

Aspell is a very powerful tool. But don't think that its only use is for external applications. Because this is Linux, you can also take advantage of the tools that other tools take advantage of. If you need more information on aspell (and all of it's options and commands - there are a LOT of them), issue the command man aspell to find out more.





  • We need your help

    Advertising revenue is falling fast across the Internet, and independently-run sites like Ghacks are hit hardest by it. The advertising model in its current form is coming to an end, and we have to find other ways to continue operating this site.

    We are committed to keeping our content free and independent, which means no paywalls, no sponsored posts, no annoying ad formats (video ads) or subscription fees.

    If you like our content, and would like to help, please consider making a contribution:

    Comments

    1. CutTheRedWire said on April 7, 2010 at 4:27 pm
      Reply

      I’ve been using this thing for years. I first used it to give Metapad a spellchecker. Now I use it as part of Notepad++: it runs the spell-check engine. The thing I love most about it is that it has so many more options for words than other programs. I find that the average word processor can’t handle the depths of my spelling… creativity. ^.^;

      Note: When using it as a part of Notepad++, they somehow created a GUI for it. o.O; I don’t know how, but it works like an old fashioned spell-checker (no red-squiggly lines). Oh, and here are two tips in using it:
      1) You can select text and just spell-check that word/phrase/paragraph
      2) You can customize your context menu and add spell-check

    Leave a Reply