Bash – Modify Command Completion for ‘cd’ to Show Only Directories

autocompletebashcd-commandls

When I am in a directory in bash, and I press cd Space Tab, it shows everything in the directory as a possibility. (Show all 1000 possibilities?) This is really cumbersome when I am in a directory with lots of regular files and relatively few directories.

So, is it possible to make the choices for autocompletion of cd to only include directories?

I know I can get a directory listing within a directory by doing

ls -d */

but I'm not sure how to proceed from there.

I am using CentOS 6.6 Final.

Best Answer

Just add

complete -d cd

in your ~/.bashrc (or other bash configuration file).