aspell Command in Linux



aspell is a command line utility in Linux that is used to check the spelling of a word, a bulk of words, or a file. It scans the entire file, finds the spelling mistakes, and shows suitable suggestions to correct the spelling.

Dont know how the aspell command works in Linux? No worries, in this tutorial, well show you different use cases of the aspell command in Linux.

Table of Contents

How to Install aspell Command in Linux?

By default, aspell command is preinstalled on most Linux distributions. However, if you encounter "aspell command not found error", it means you have accidentally removed it. To reinstall the aspell command, you can use your default Linux repository and install the command through the system's package manager.

For Debian-based system users, the following apt command is used to install the aspell command on the system.

sudo apt install aspell

The REHL users can install aspell command on their systems using the yum package manager and the command is provided below −

sudo yum install aspell

In case you are using CentOS or Fedora system, then use the following command to install aspell command on your system −

sudo dnf install aspell

Syntax for aspell Command in Linux

You can use the aspell command in Linux with different options; each option serves a specific functionality. To use this command, follow the mentioned syntax −

aspell check [options] file_name

Here, file_name is the name of the file you want to spell check. You can replace [options] with various flags that modify the behavior of aspell.

Different Options Available for aspell Command in Linux

The table below illustrates all valid options of the aspell command along with their respective functionality −

Option Functionality
-a Spelling checker for a single word.
-c Check the spelling of a complete file.
-list Checks spelling of multiple/bulk of user-entered words.
-v It shows the version of the aspell command.
-mode=mode It specifies the mode that we used for spelling checking.
-dont-backup Use this option with the aspell command to prevent generating a backup file.
-encoding=name It specifies the format that the file is supposed to be in.
-lang=name -l name It specifies the language to be utilized for spelling checking.
-sug-mode=mode It specifies the suggestions mode of the aspell command.
ignore-case=true/false By default, aspell is case-sensitive, but you can set it to ignore the case using the "ignore-case" option.

Alternatively, you can run the aspell command with the "-?" option to get the summary of aspell command and its options −

aspell -?

Examples of aspell Command in Linux

Lets discuss a few examples of the aspell command on Linux provided in this section below.

Check the Entire File for Spelling Mistakes

The following aspell command scans the entire "example.txt" file for spelling mistakes and shows the suitable suggestions −

aspell -c example.txt
aspell Command Linux 1

Now you can replace the incorrectly spelled words with the correct spelling or ignore the suggestions, as instructed in the above screenshot. For example, to replace the word "hllo" with "hello", first, type "r" and then type the suggested number or the correct spellings. Finally, press the "x" key on your keyboard to save the changes in the file and return to the terminal.

Check a Single Word for Spelling Mistakes

You can execute the aspell command with the "-a" option to check a single word, as shown in the following syntax −

aspell -a 

When you run this command, it will wait for user input; type a word and press enter. As a result, the aspell command will scan the user-entered word for spelling mistakes and display spelling suggestions on stdout, as follows −

aspell Command Linux 2

Check a Bulk of Words for Spelling Mistakes

We can check a bulk of words for spelling mistakes by executing the aspell command with the "list" option, as follows −

aspell list

When you run this command it lets you enter as many words as you want. Once you enter all the words, press "CTRL+D" and the aspell command will scan each word for spelling mistakes and show the incorrectly spelled words on stdout, as shown in the following screenshot −

aspell Command Linux 3

Specify a Mode to Check Spelling

The aspell command can be executed with the "-m" or "-mode" option to specify the mode used for spell-checking. For example, the following code checks the spelling of an HTML text using the aspell command −

echo "<h2>Chking spelling of an HTML text</h2>" | aspell -a --mode=html

The aspell command scans the HTML text and shows the spelling suggestions for the incorrectly spelled words −

aspell Command Linux 4

Exclude Words of Specific Length from Spell Check

We can use the "ignore=n" option to avoid words of specific length from spell-checking. For example, if we specify "ignore = 4"; aspell will not check the words of length 4 for spelling mistakes −

aspell -c --ignore=4 example.txt

The output shows that the aspell command didnt check a 4-character word for spelling. However, it checks words with lengths other than 4 for spelling mistakes and shows suitable suggestions for the incorrectly spelled words −

aspell Command Linux 5

Spell Check With Different Suggestion Modes

We can use the aspell command with the "-sug-mode" option to specify different suggestion modes for the incorrectly spelled words. These suggestion modes include "normal", "fast", and "ultra". Lets understand how the "sug-mode" option works in Linux using the following example −

echo "Let's Chek Spelling Mistakes" | aspell -a --sug-mode=normal

This command will scan the input text for spelling mistakes and show detailed suggestions as follows −

aspell Command Linux 6

Similarly, you can specify the "fast" or "ultra" modes to get the spelling suggestions accordingly.

Difference between ispell and aspell

Both "ispell" and "aspell" commands are used in Linux to check spelling mistakes. The ispell command is the older one from GNU and has limited capability to read various types of encoded files. On the other hand, aspell is an interactive utility that checks spelling via standard input or by scanning the file.

Conclusion

aspell is a handy command line tool in Linux for checking spelling. Whether you need to check a single word, multiple words, or an entire file, aspell can handle it efficiently. It examines your file, identifies any spelling mistakes, and provides recommendations to help you fix them. Also, you can replace the incorrectly spelled word with a suitable suggestion, ignore the given suggestions, or add the spelling to your dictionary.

The aspell command supports several options to perform specific functionalities, such as "-c" to check a complete file for spelling mistakes, "-a" to check an individual word, and the "list" option to check multiple words. Apart from these options, you can also use options like "-ignore-case", "-ignore=n", "-dont-backup", "-sug-mode=mode", etc., to achieve different purposes.

Advertisements