How To Automatically Correct Spelling Mistakes And Typos When Using “cd” On Linux

  • 408
  •  
  •  
  •  
  •  
  •  
  •  
  •  
    408
    Shares

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. This article will 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.

You can add commands 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 need to add a command to the .bashrc file. To edit the .bashrc file one must use gedit.

Type the following command at the prompt:

gedit ~/.bashrc

You can use any text editor such as vi and nano. Just replace “gedit” in the above command with the text editor you want to run.

Now 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 type in the description you want to add. After have added the command to the file, click “Save“.

03_adding_cdspell_to_bashrc

Now close gedit (or other text editor) by clicking the “X” in the upper-left corner of the window. 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.

Note: 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.

The following two tabs change content below.

Unallocated Author

Please note that the article you are reading has an unallocated author as the original author is no longer employed at latesthackingnews.com, this has been put in place to adhere with general data protection regulations (GDPR). If you have any further queries, please contact: [email protected]

Unallocated Author

Please note that the article you are reading has an unallocated author as the original author is no longer employed at latesthackingnews.com, this has been put in place to adhere with general data protection regulations (GDPR). If you have any further queries, please contact: [email protected]

Leave a Reply