Breadcrumbs 
Learning >> Documentation >> Using the Shell >> Tab completion
 
Recent News
We're No 1!
We've reached the top! (Of Google!)
[ more ]
Firefox 3 Download Day
Firefox 3 has been officially released and is looking to set a world record for the most downloaded piece of software in 24hrs.
[ more ]
SSL Renewed
SSL cert has been renewed by the admin team.
[ more ]
Tab Completion
Tab Completion

Imagine you have two files in your directory, 'aaaaaaaaaaa' and 'bbbbbbbbbbb'. Suppose you wanted to view 'aaaaaaaaaaa'. Rather than have to type its long and cumbersome name, in bash all you have to do is type:

$ less a<tab>

When you press tab, you say to the shell "look for any files that start with a". If there's only one file, then it's name is completed. You are using "tab completion".

Suppose you created another file, 'abaaaaaaaaa'. If you typed what you see above, you would get:

$ less a<tab>
aaaaaaaaaaa abaaaaaaaaa

Here there is more than one file that matches what you have told bash about it, so it can't decide between them. So it tells you what files it can't decide between and lets you supply more information (in this case, the second letter.) So if you want to get 'aaaaaaaaaaa', you'd have to type:

$ less aa<tab>

And now there's only one file that fits that description.

Note that you can also use tab completion for telling bash what program you want to use, not just what files to pass to it. For example:

$ d<tab>
Display all 182 possibilities? (y or n) n

Here there are far too many possible commands to list. You haven't told enough.

$ da<tab>
dash-search data2inc date

Here you have to decide between 3 different programs.

$ date
Sat Aug 2 12:12:20 IST 2003

This is very useful for finding out about commands that you didn't know about. Experiment!

Next we'll look at scrolling.

In this section