Filename Completion


It can be difficult and time-consuming to type in long filenames. As you have seen, wildcards (such as *) can be used as shortcuts for filenames, but they can also cause mistakes-for example, if there are several files in the current directory that start with the same letters. Filename completion is a feature first introduced in csh that gives you a better shortcut for entering filenames.

Suppose the current directory contains the following files:

 % ls california newjersey newyork washington

If you type the letters cal in a command line and then press the TAB key, the shell will fill in the filename california for you. (In csh and some versions of ksh, you press the ESC key twice instead of using TAB. The public domain version of the Korn shell, pdksh, does support tab completion.) So the line

 $ cat cal [TAB]

becomes

 $ cat california

If more than one file in the directory starts with those letters, the shell will fill in as much as it can. So

 $ rm n [TAB]

becomes

 $ rm new

You can then add more letters, and press TAB again to complete the rest. In bash, you can type TAB twice in a row to see a list of all the files beginning with the same letters:

 $ rm new [TAB] [TAB]                       # bash only newjersey newyork

The newer shells, tcsh, ksh, and bash, have filename completion (also known as tab competition) turned on by default. In csh, you have to enable filename completion by setting the toggle variable filec. In ksh, the command-line editor you have selected may affect filename completion-see the FAQ on the Korn shell web site (listed at the end of this chapter) for more information.




UNIX. The Complete Reference
UNIX: The Complete Reference, Second Edition (Complete Reference Series)
ISBN: 0072263369
EAN: 2147483647
Year: 2006
Pages: 316

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net