I am using Centos 7 and bash. I know on some machines, if there is only one subfolder (and some files) in current folder, when you type cd <tab> it will auto-complete the name of the subfolder. However, it doesn't work on my machine, although <tab> can do other auto-completion on my machine, e.g., less ab<tab> will auto-complete the filename starting with ab. How can I fix it?


Another working machine has same Centos and bash. On my machine, cd <tab> does nothing but a beep. For cd <tab><tab>, it shows all files and the single subfolder in current folder. The single folders on both machine are proper (command ls -ld the_single_folder shows drwxrwxr-x 2 user user ...).

Some shell options (output of command shopt) are different. The output of diff shoptA shoptB is (my machine is B):

< extglob           on
> extglob           off
< hostcomplete      off
> hostcomplete      on
> syslog_history    off

I tried to change those different options (extglob and hostcomplete) on my machine using commands shopt -s extglob and shopt -u hostcomplete. But it didn't work

Command complete -p cd on that machine output complete -o nospace -F _cd cd, on my machine output -bash: complete: cd: no completion specification.

Command type _cd on that machine output:

_cd is a function
_cd () 
    local cur prev words cword;
    _init_completion || return;
    local IFS='
' i j k;
    compopt -o filenames;
    if [[ -z "${CDPATH:-}" || "$cur" == ?(.)?(.)/* ]]; then
        _filedir -d;
        return 0;
    local -r mark_dirs=$(_rl_enabled mark-directories && echo y);
    local -r mark_symdirs=$(_rl_enabled mark-symlinked-directories && echo y);
    for i in ${CDPATH//:/'
        for j in $( compgen -d $i/$cur );
            if [[ ( -n $mark_symdirs && -h $j || -n $mark_dirs && ! -h $j ) && ! -d ${j#$i/} ]]; then
    _filedir -d;
    if [[ ${#COMPREPLY[@]} -eq 1 ]]; then
        if [[ "$i" == "$cur" && $i != "*/" ]]; then
    return 0
  • probably there's nothing to fix, and there's a good reason this is happening. What happens if you press <tab><tab>? Jun 20, 2021 at 12:50
  • also, this might sound like a stupid question, but on these other machines, are you using the same bash? Or is it dash/zsh/something else? echo $SHELL might be a quick way of figuring out. Jun 20, 2021 at 12:58
  • <tab><tab> showed all files and that subfolder on my machine, as most machines do. On another machine, it has same bash and Centos as shown by commands ps -p $$ and cat /etc/os-release. But it works well.
    – M. Fayer
    Jun 20, 2021 at 13:34
  • ok, so cd <tab><tab> in the folder you're expecting cd <tab> to work (but where it doesn't work) lists exactly one folder? Or none? Jun 20, 2021 at 13:57
  • 2
    I wonder if completions for cd come with bash or you need extra package(s) maybe. Jun 20, 2021 at 15:47

1 Answer 1


Following the link in @Kamil Maciorowski 's suggestion, I installed a package by command

yum --enablerepo=epel install bash-completion-extras

It solved my problem. Thank you all!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .