I am using Ubuntu 20.04. The su autocomplete stopped working. For example when I type:

su TabTab

It lists the files and directories of the current directory, where as it should list the available users.

Bash auto-complete for other commands is working fine for example:

apt-get TabTab

It lists the available apt-get options.

usermod TabTab

It lists the available user accounts.

su was working fine before and now it is not. I have no idea when it stopped working.

I have checked other questions but most of them are related to bash-completion, not specific to su. So, before marking it duplicate please check the existing answer if it addresses su.

3 Answers 3


Finally found the solution.

It is not an issue but due to the changes in the implementation of su command on Ubuntu-20.04.

Here is the workaround:

Edit the following file:

sudo vi /usr/share/bash-completion/completions/su

Replace line 44:

COMPREPLY=( $(compgen -f -- $cur) )


COMPREPLY=( $(compgen -u -- $cur) )

Source-1: https://stackoverflow.com/a/53417028/8388883

Source-2: https://github.com/scop/bash-completion/issues/253#issuecomment-440591431

The sources are for CentOS, but also working for Ubuntu 20.04.


Solved with sudo apt-get install bash-completion -y and then source ~/.bashrc

Source: https://askubuntu.com/questions/133086/bash-tab-auto-complete-not-working-for-apt


In 20.04, you can use the following commands by default to make use of autocomplete:

sudo -u TabTab
su - TabTab

You must log in to answer this question.

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