Wednesday, June 19, 2013

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
fi

Then type this in a terminal to reload:
bash


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

found at http://www.webupd8.org/2010/03/how-to-autocomplete-commands-preceded.html

2 comments:

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

    $ source .bashrc

    ReplyDelete

Cybermap

Internet Storm Center Infocon Status

Internet Storm Center Infocon Status
Internet Storm Center Infocon Status