How To Autocomplete Commands Preceded By 'sudo'

When writing a command in the terminal, you can autocomplete it by pressing the TAB key. Example: type "nau" in the terminal and press TAB -> "nautilus" should show up (if you have Nautilus installed, obviously).

However, the autocomplete doesn't work if you are trying to run a command with "sudo". For example, typing "sudo nau" and then pressing the TAB key will not autocomplete the command to "sudo nautilus".

Here is how to get autocomplete to work in the Terminal while using "sudo". Simply open the ".bashrc" hidden file from your home folder. If you use GNOME, paste this in a terminal to open it:

sudo gedit ~/.bashrc

Then paste this at the bottom of the file:
if [ "$PS1" ]; then
complete -cf sudo

Then type this in a terminal to reload:

Now try the example in the beginning of the file "sudo nau" and press TAB. It should now work.

found at


  1. Instead of launching another bash process to reload .bashrc you can simply do:

    $ source .bashrc


Post a Comment

Popular posts from this blog

How to clean DB from old logs in Magento 1.x

Reduce (shrink) and resize raw disk at Proxmox

Apache 2.4 + mod_wsgi + Python 3.7 + Django installation on Centos 7.10