Tab (Auto-complete) and Tab-Tab (Auto suggest)

On your Bash or ZShell prompt while you navigate the file system, hit tab once. It will “type for you” — automatically matching what it thinks you want—  until it finds two files with the same name. Then it will go as far as it can, completing only up until the letters provide a match that it can distinguish. If such a unique matching file name exists in the file system, it will automatically complete the matching filename for you and put a space.

In the previous lesson, we learned that we can use the ls command to list out items in a directory. We can pass a first argument to ls, and like file-based UNIX commands, ls takes a Unix path matcher. As we also learned in the previous lesson, a path matcher is where we can specify only a part of a path name and tell the command to apply itself on any file or folder paths that match the value— mosty typically, this means a “starting match” which is what we refer to as matching the characters at the start of the string specified.

Hit tab to auto-complete, tab-tab to auto-suggest, and if you have no matches the interface will ‘blink’ 3 dots at you or tell you explicilty.


No Match

Consider I’m in a directory and I want to list only the files that begin with the letter x

Type ls x and hit return.

There are no files in this directory that match x, so the interface “blinks” (flashes) 3 dots at me to tell me this. (Somesystems might tell you explicitly)

Let’s suppose instead of hitting ruturn, I hit the tab key — the auto complete & auto suggest, to ask Unix to tell me what files in this directory begin with x

When there is no match, pressing tab will show three dots ‘blink’ telling you there is no match.

When there are no files that begin with the string, hitting tab will show three dots momentarily and then make them disappear. This tells me there are no matches for files or folders that begin with the letter x.

Multiple Matches

If there are more than one match for the starting characters, your shell will complete up to the point of the first character that differs between the matching files.

If it makes a completetion, it doesn’t show suggestions. That’s why I said above “tab for auto-complete and tab-tab for auto-suggest.”

Exact Match

Unix completes the rest of the file path for you up to the point where it can create a distinct file path.

If it can, it completes the file. If there are more than one match for the starting characters, it complete up to the point of the starting character.