Tab Completion

From Coder Merlin
Within these castle walls be forged Mavens of Computer Science ...
— Merlin, The Coder


Very often, the shell can help us to complete file and directory names when we begin to type the name of a file (or directory) and then type TAB. Try it now. Type "cd M" and then press TAB. The shell will complete the rest of the name by appending "erlin" to what you’ve already typed. Then press ENTER. Because the completion is not ambiguous (i.e. there is only one solution) the shell will complete the name. If there were multiple possibilities, the shell would complete as much as possible and then beep. At this point, we could press TAB twice in succession to see the possible completions. Let’s try this. Within the Merlin directory, create three new directories: hello, hello2, and hello3:

john-williams@codermerlin:~/Merlin$  mkdir hello

john-williams@codermerlin:~/Merlin$  mkdir hello2

john-williams@codermerlin:~/Merlin$  mkdir hello3

Then, type “cd h”:

john-williams@codermerlin:~/Merlin$  cd h

Now, press TAB. The shell will complete as much of the name as possible and then beep. (Depending on your terminal you may not hear the beep or you may see a flash.)

john-williams@codermerlin:~/Merlin$  cd hello

Now press TAB twice in succession. The shell will display matching possibilities and then provide a new prompt followed by the previous entry:

hello/ hello2/ hello3/ 

john-williams@codermerlin:~/Merlin$  cd hello

You now have the option of pressing ENTER to accept "hello" or adding some more characters (in this case “2” to form “hello2” or “3” to form “hello3”) and then pressing ENTER to execute the command as-is or TAB to search for additional completions. In our case, let’s press ENTER to descend into the "hello" directory:

john-williams@codermerlin:~/Merlin$  cd hello

john-williams@codermerlin:~/Merlin/hello$