next up previous contents
Next: I/O Redirection Up: Advanced Topics Previous: Advanced Topics   Contents

TAB Completion

In tcsh, bash, and many other shells, filenames and commands can be completed or partially completed automatically by pressing the TAB key. This is commonly known as TAB completion. Pressing TAB after typing in a shell prompt will complete the filename, directory name, or command name as far as it can (or completely if it can be uniquely determined from the currently typed letters).

For instance, if you are in your home directory, type cd pr then press the TAB key. Since no other files or directories in your home directory (by default) begin with ``pr'', the shell can determine that you mean to type ``private'' to refer to your private directory. You can then continue entering arguments into the command, or you can press Enter to execute the command.

In addition, TAB completion can be used to partially complete names. Suppose that there are 3 subdirectories in one of your directories for each of your programming assignments, named program1, program2, and program3, and nothing else. While in this directory, you can type cd p and press TAB and the shell will complete the command as far as ``program,'' however it does not know which program directory you mean. You will have to finish the directory name yourself.

Please note that tab completion can be done with most every command. The cd command was merely used as a common example. If you type em at a prompt and press tab, ``emacs'' will be completed since the shell can determine that no other command begins with em.

However, TAB completion has its limitations. In the first example, if you typed cd p and pressed TAB, nothing would get added to the command and the computer would likely beep at you. This is because the file you want to enter cannot be uniquely determined by the shell. It does not know whether you want to choose your public or private directory. You need to give the shell more information before TAB completion will work.

To list all possible completions of a command or file, if you use tcsh (the default shell), type CTRL-D after partially completing the command. If you use bash, press TAB twice instead. If you type cd p in your home directory and pressed CTRL-D (or TAB twice), a line will appear with ``public/'' and ``private/'' indicating the two possible completions. As always, please consult the manual page of your shell for more information and specifics about how it handles TAB completion.


next up previous contents
Next: I/O Redirection Up: Advanced Topics Previous: Advanced Topics   Contents
Michelle Craft 2008-01-23