Tips

Checking Spellings in Linux Command Line

Linux command line is versatile. There are commands that can be used to perform spellcheck and find out misspelled words. Here's how!

Abhishek Prakash
Abhishek Prakash

In this age, spellchecking is built in almost anywhere you write text be it your browser, text editor or your word processor.

But back when internet wasn’t readily available and people were stuck to just the command line, spelling check was a luxury.

This is why earlier operating system like Unix and Linux provided some built-in spellcheckers and dictionary features. Surprised? Let me show you such commands.

Linux commands for spelling check and dictionary

Linux Spellcheck Command
Linux Spellcheck Command

You may find these built-in spellchecker quite primitive in comparison to the modern, graphical ones, but it could be useful in scripting and some other rare cases.

Let me show you some commands that you can use for spellchecking and dictionary.

1. look command for finding words starting with a string

Don’t confuse it with the locate command which is used for finding files. The look command prints all the words starting with a given string. If it finds nothing, it displays nothing.

[email protected]:~$ look bigg
Biggles
Biggles's
bigger
biggest
biggie
biggie's
biggies

You can use the -i option to ignore case.

Where does it get the dictionary from? Well, every Linux system has a ‘dictionary’ located in /usr/share/dict/words file. This file basically contains one word per line, sorted alphabetically.

You can also provide your own file. If it’s not alphabetically sorted, the search only goes as far as it can go in alphabetically ascending order from the top.

2. aspell command for interactive spell checking

The aspell is an interactive spellchecker. It checks the file and presents you alternatives for the words it doesn’t recognize.

aspell -c filename.txt

You can also use it to replace all the occurrences of the wrong word with the correct alternate choice. You can also ignore the misspelled word and it will show the next misspelled word.

Aspell Linux Command Example

As you can see in the image above, it also shows you all the options for navigating and handling the misspelled words.

3. spell command for finding all misspelled words

If you just want to list all the misspelled words in a file, the spell command is what you need. Unlike aspell command above, this command is not interactive.

spell filename

Here’s the text file that I am going to run spellcheck on:

[email protected]:~$ cat a.txt 
my text file
som words mayeb wrong
but what can i do?
oh, I can use spellchecke r

And you can see that the spell command works nicely.

[email protected]:~$ spell a.txt 
som
mayeb
spellchecke

I hope you liked this Linux command tip. Stay tuned for more Linux learning.



Join the conversation.