31

I have just came across something that is really bothering me. Autocompletion on ubuntu works like a charm but when I login as root, e.g. su I get tab autocompletion only sometimes.

Why does it work like that? Can one change that?

Braiam
  • 69,112
Patryk
  • 9,416

5 Answers5

58

Check your /root/.bashrc file for these lines

if [ -f /etc/bash_completion ]; then
  . /etc/bash_completion
fi

If they do not exist add them to the end of the file using your favorite text editor.

Please note, that the autocompletion will start working just after logging out and back again!

Frantique
  • 8,673
Bruno Pereira
  • 74,715
9

You haven't mentioned which Ubuntu version you use.

  • Check if you have the bash-completion package installed:

    sudo apt-get install bash-completion
    
  • Mine works if I login using: sudo -i

3

For Ubuntu 13.10, check /etc/bash.bashrc for

# enable bash completion in interactive shells
if ! shopt -oq posix; then
  if [ -f /usr/share/bash-completion/bash_completion ]; then
    . /usr/share/bash-completion/bash_completion
  elif [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
  fi
fi

They might be commented. Un-commenting them works.

kiri
  • 28,986
dbtek
  • 131
0

Found that this worked (similar to the answers above but with a twist)

The file that needs to be edited (at least in my case with 12.04) was /root/.bashrc. This makes sense in my case, given that my regular user was autocompleting just fine but my root wasn't.

Anyway in said file I found all the necessary code but it was commented out:

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
#if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
    #. /etc/bash_completion
#fi

Just un-commented it:

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
    . /etc/bash_completion
fi

Saved, and it worked just fine.

Hope this helps someone.

neanderslob
  • 756
  • 2
  • 9
  • 25
0

In Linux Mint 18 (based on Xenial), you have to edit your bashrc :

sudo nano /etc/bash.bashrc

and comment out (remove the # in front of each line) this section :

if ! shopt -oq posix; then
  if [ -f /usr/share/bash-completion/bash_completion ]; then
     . /usr/share/bash-completion/bash_completion
  elif [ -f /etc/bash_completion ]; then
     . /etc/bash_completion
  fi
fi

That’s all.