Bash Completion - Makes life easier for Linux users

September 13, 2005
One thing that really makes working in the command line in Linux a pleasure is the various in-built shortcuts and name completion features in Bash - the default shell in Linux.

But one grouse I always had was it was really difficult to remember all the options that each command had. For example, 'find' came with numerous options which I found difficult to memorize and had to resort to reading the man page each time I had to use the command. Now you can enhance the bash shell to give you the added functionality of listing the options that can be used with a command. For that you should download and install an add-on package called bash-completion. I use Fedora Core 2 but if you are using the latest Linux distribution, it might be installed by default on your machine.
In Debian based Linux distributions, you may install it using the following command :
# apt-get install bash-completion
After installing the bash-completion package, fire up a terminal and type:

$ grep --

... followed by two TABs and you get all the options that can be passed to the grep command (see figure). This works for any command in linux. Now you don't have to remember all those options that need be passed to the programs any longer.

bash completion
Also read:
Bash Shell Shortcuts
Special Shell Variables

4 comments:

  • Zeth

    Great stuff, Bash completion is worth its weight in gold in my opinion.

    Gentoo users, you just need to do:

    # emerge bash-completion

    For extra coolness, this will install extras for Gentoo:

    # emerge gentoo-bashcomp

    Now for say,

    # emerge mozilla-firefox

    You just need to type (where | = Tab):

    eme| moz|f|

    Best Wishes,
    Zeth
    (Command Line Warriors)

  • I particularly like bash completion with ant. i don't have to invoke -projecthelp to see the list of available targets anymore.

  • Cd-MaN

    And best of all: it is installed by default in Ubuntu :)

  • dreaming in the morning

    Very very useful!! Thanks!

    I want to clarify one thing: with certain commands, if 'command' followed by 2 dashes fails, try typing only one dash.

    For example command 'find' only works if you type
    find - [2 tabs], just because all find switches are preceded by one dash.

    Bye!