Make CD Command Case Insensitive in Bash – How to Guide

bashcd-commandshell

Sometimes while accessing the various directories it happens most of the times that I remember the names or at least part of the names of a directory under our Linux system. But some of the directories are named starting with first character caps or one of the characters in the middle of the name Upper case.

Can anyone suggest how can I make the arguments following cd command case INSENSITIVE, such that if I perform cd BackupDirectory or cd backupdirectory it could enter the directory name BackupDirectory.

Of course I don't want to screw the things for other users so if the above is possible, is that possible that the change could be applied just to the session I am using and do not effect other users?

Ok, I tried set completion-ignore-case on but this just doesn't work. It just helps in that if I type cd b and Tab or Esc Esc it fills the directory name ignoring the case. But, what I need is if I do a cd backupdirectory, it just ignores the case and enters BackupDirectory on its own.

Best Answer

Enabling cdspell will help:

shopt -s cdspell

From the man page:

cdspell If set, minor errors in the spelling of a directory component in a cd command will be corrected. The errors checked for are transposed characters, a miss- ing character, and one character too many. If a correction is found, the corrected file name is printed, and the command proceeds. This option is only used by interactive shells.

Related Question