Thursday, 20th November 2008
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.