Autocompletion doesn't work while logged as root

30,318

Solution 1

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.

Solution 2

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

Solution 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.

Share:
30,318

Related videos on Youtube

Patryk
Author by

Patryk

Software Engineer C++/Go/shell/python coder Linux enthusiast Github profiles: https://github.com/pmalek https://github.com/pmalekn

Updated on September 18, 2022

Comments

  • Patryk
    Patryk almost 2 years

    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?

    • Admin
      Admin over 12 years
      Are you actually logging in as root, or using sudo su?
    • Admin
      Admin over 12 years
      @MartyFried Yes I am diong sudo su. What is the difference?
    • Admin
      Admin over 12 years
      It seems to work for me, can you provide us with a specific instance of when it does not work, something that we can replicate.
    • Admin
      Admin over 12 years
      @lordmonkey: Maybe none, I'm not really sure. I think su or sudo su by itself is a little different in some way that I don't remember, so I wanted to make sure that I could check this under the same conditions. It seems like it works, but you said "sometimes", so I can only suggest you double-check and try to make it reproducible, or just make sure there's not something else happening that is fooling you - ie, user error - hey, it happens to everyone! :)
  • geirha
    geirha about 12 years
    What's the point of removing root's .bashrc?
  • geirha
    geirha about 12 years
    No, a new .bashrc will not be created, and /etc/bash_completion will not be sourced, only bash's default completion will be available.
  • macrobook
    macrobook about 12 years
    OK, edited and removed. Thank you for your input! Though I wonder if ~/.bashrc can "unsource" a file or if disable-completion is still available: superuser.com/questions/37148/…
  • Ankit
    Ankit almost 12 years
    Mine .bashrc contained the mentioned lines but they were commented out; uncommented the lines and sourced the new .bashrc ; things look pretty good now .
  • Peregring-lk
    Peregring-lk over 7 years
    The bash_completion line, at least in my case, were commented out, because it claims the bash_completion is already enabled in /etc/bash.bashrc, but that file has also that lines commented out. Instead of uncommenting the etc file, it's better to uncomment the line in /root/.bashrc.