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 press TAB. Try it now. Type "cd M" and then press TAB. The shell completes 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 completes 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" as below:

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

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

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

Now press TAB twice in succession. The shell displays matching possibilities and then provides 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 go to the "hello" directory:

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

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