Is it standard behaviour for cd to automatically choose when given an incomplete directory name?

I have three folders called ProjectA, ProjectB and ProjectC. When I tab-complete cd to cd Project and press Enter, it chooses ProjectC. I’ve found this is also the case with other similar cases; it defaults to the last in lexicographic order (but this may also be most recently changed/added).

Is this expected default behaviour for cd, or have I set something by accident here?

I’m running OSX 10.10.3, with bash 4.3.

Asked By: Rob Holt


I don’t encounter that behavior. But I was able to reproduce it. Maybe you accidentially changed the option cdspell. See the Bash Reference Manual:


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 missing character, and a character too many. If a
correction is found, the corrected path is printed, and the command
proceeds. This option is only used by interactive shells.

I tried it and it always corrects the path in the argument given to cd. If there are multiple possibilities like in your folder with ProjectA, ProjectB and ProjectC, it defaults to the one that is the last in the directory order. You can check that by ls -U. See the example:

user@host:~$ ls -Ul
total 0
drwxr-xr-x 2 root root 40 May 26 08:11 ProjectA
drwxr-xr-x 2 root root 40 May 26 08:11 ProjectB
drwxr-xr-x 2 root root 40 May 26 08:11 ProjectC
user@host:~$ cd Project<tab><tab>
ProjectA/ ProjectB/ ProjectC/
user@host:~$ cd Project

To disable that behavior use:

shopt -u cdspell
Answered By: chaos
Categories: Answers Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.