We’re used to word processing programs telling us when we’ve misspelled a word, but what about when your fingers are flying through directories on the Linux command line? You can actually have your typos and misspellings automatically corrected, at least when using the
We’ll show you how to add a simple command to the .bashrc file that will check what you type into the cd command for transposed characters, missing characters, and too many characters.
RELATED: How to Add Tabs to Ubuntu's Terminal
The .bashrc file is a script that runs every time you open a Terminal window by pressing Ctrl+Alt+T or open a new tab in a Terminal window. You can add commands to the .bashrc file that you want to run automatically every time you open a Terminal window. To add a spell check to the cd command, we’re going to add a command to the .bashrc file.
To edit the .bashrc file, we’re going to use gedit. Type the following command at the prompt.
Scroll to the bottom of the .bashrc file and add the following line to the end of the file.
shopt -s cdspell
You can add a comment above the command so you remember what the command does. Simply put a number sign (#) at the beginning of the line, and then any description you want to add.
Close gedit (or other text editor) by clicking the “X” in the upper-left corner of the window.
The setting you just added to the .bashrc file will not affect the current Terminal window session. You must close the Terminal window and log out and back in for the change to take affect. So, type
exit at the prompt and press Enter or click the “X” button in the upper-left corner of the window. Then, log out and back in.
Now, if you make a small mistake (such as transposed characters) when typing the name of a directory in the cd command, the correct spelling displays on the next line and you are automatically taken to the directory that most closely matches what you typed.
This is a simple solution that makes navigating directories on the command line much easier.