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.
Related videos on Youtube
![Patryk](https://i.stack.imgur.com/jTqPB.png?s=256&g=1)
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, 2022Comments
-
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 gettab
autocompletion only sometimes.Why does it work like that? Can one change that?
-
Admin over 12 yearsAre you actually logging in as root, or using sudo su?
-
Admin over 12 years@MartyFried Yes I am diong
sudo su
. What is the difference? -
Admin over 12 yearsIt 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 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 about 12 yearsWhat's the point of removing root's .bashrc?
-
geirha about 12 yearsNo, a new
.bashrc
will not be created, and/etc/bash_completion
will not be sourced, only bash's default completion will be available. -
macrobook about 12 yearsOK, 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 almost 12 yearsMine .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 over 7 yearsThe
bash_completion
line, at least in my case, were commented out, because it claims thebash_completion
is already enabled in/etc/bash.bashrc
, but that file has also that lines commented out. Instead of uncommenting theetc
file, it's better to uncomment the line in/root/.bashrc
.