Hack 6. Use “shopt -s cdspell” to automatically correct mistyped directory names on cd

Use shopt -s cdspell to correct the typos in the cd command automatically as shown below. If you are not good at typing and make lot of mistakes, this will be very helpful.

# cd /etc/mall
-bash: cd: /etc/mall: No such file or directory

# shopt -s cdspell

# cd /etc/mall

# pwd

[Note: By mistake, when I typed mall instead of mail,
          cd corrected it automatically]

Comments on this entry are closed.

  • Sathish January 26, 2011, 12:33 am

    very useful.
    But I think the scope of “shopt -s cdspell” command is in the current terminal only.
    How can i set it permanently so that whenever i login it will correct my typo error.


  • Abhinav Chittora February 27, 2012, 2:05 am

    @Sathish, you can make “shopt -s cdspell” command permanent using adding this line to your bash_profile file. You bash_profile is located in your home directory.

    $vi ~/.bash_profile
    shopt -s cdspell

    Save the file. You need to log out once and login again to make it permanent. After this, you need not to type this command for each terminal.