Tab-Completion

Written by Chris Gregg, with modifications by Nick Troccoli

Click here for a walkthrough video.

One extremely time-saving feature built into the Bash Shell is the ability to "tab-complete" commands. Simply hit the tab key while you are typing a command, and the shell will automatically finish the command for you. Or, if it is ambiguous, it will provide options (you might have to type tab again). For example, if you want to type the history command, you can type his-tab and the rest of the command will be filled in:

$ his (then hit tab, at which point the entire history command will show)
$ history
...

If, on the other hand, you typed hi and then tab twice, you would see this:

$ hi (then the tab key twice)
hipercdecode hipsopgm history
$ hi

The shell is telling you that there are three commands that start with hi, and you have to continue with the letter you know is next. Then, if you type tab again, you can finish the completion.

Tab completion is extra-handy when you want to type file names or directories. Instead of typing a long file name, you can simply start typing a name and then type tab to have the name autocomplete. If only part of the name completes, that means there are multiple options, and typing tab again will give you the options that the shell is considering.