## 3.5. Completing File and Directory Names

Most Unix shells can complete a partly typed file or directory name for you. Different shells have different methods. In many shells, you type the first few letters of the name, then press TAB. If the shell can find just one way to finish the name, it will; your cursor will move to the end of the new name, where you can type more or press RETURN to run the command. (You also can edit or erase the completed name.)

What happens if more than one file or directory name matches what you've typed so far? Again, that depends on the shell you're using. The cursor will probably stay where it is, and the terminal may beep. At this point, the easiest answer could be to type more characters of the name (to make the name unique) and press TAB again to complete the rest of the name. You may also be able to get a list of all possible completions; after the first beep, try pressing TAB again (or CTRL-D, depending on your shell) and you may see a list of all names starting with the characters you've typed so far. Here's an example from the bash shell:

>     $ cp /etc/paTAB(beep)TAB
>     pam.d         paper.config  passwd        passwd-       passwd.OLD
>     $ cp /etc/pa

At this point, I could type another character or two--an s, for example--and then press TAB once more to make `/etc/passwd`.

Copyright © 2003 O'Reilly & Associates. All rights reserved.