Bash Completion Doesn't Work In Root User

Solution 1:

Bash completion can be enabled in the file .bashrc as explained in this Q&A. In your case it seems to be correct in your user's .bashrc, but not in your root's .bashrc. The latter file is located in /root/.bashrc. Open this file with your favorite text editor as root (e.g. by running sudo gedit /root/.bashrc) and remove the # in the beginning of the last three lines:

You have to change the lines 98-100 from

#if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
#    . /etc/bash_completion
#fi

...to:

if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
    . /etc/bash_completion
fi

Then close your terminals and reopen them.

Solution 2:

I successfully enabled "bash completion" in Ubuntu 12.04 LTS by editing the file "bash.bash.rc" in "etc".

I just removed the "#" in lines 32-34 and bash completion for "sudo" works fine now.