Working on the Linux command line: How to bash `cd` with autocorrect

Updated . Posted . Visible to the public. Repeats.

There is an option you can set so that when using the cd command, small typos are automatically corrected. Add the following to your ~/.bashrc:

# cd: autocorrect small typos and use best guess
shopt -s cdspell 

Example:

cd Porjects
# Projects

pwd
# /home/judith/Projects

Also, I recommend adding aliases for your most common typos of commands you regularly use to your ~/bashrc. Which ones that are is highly personal, for me it's e.g. tig:

alias tog='tig'
alias tug='tig'
Profile picture of Judith Roth
Judith Roth
Last edit
Michael Leimstädtner
License
Source code in this card is licensed under the MIT License.
Posted by Judith Roth to makandra dev (2021-09-17 17:09)