Text Completion Feature in Dos and Unix

There are some features in Unix that are very powerful, especially the commands. I am very much interested in these commands and today want to share one such general command which may be of use many times, and not just for geeks!. We have also included the corresponding DOS command, as our analytics stats show that most of our readers are yet using windows!

Text Completion Feature ?
Text completion is a feature built into some Unix shells that allows you to type part of a filename or directory name and press a key to fill out the rest.

DOS:- Text Completion Feature
In DOS we make use of tab button.
Ex:-

c:\>cd Doc[tab]

this will automatically take the full folder name as

c:\>cd “Documents and Settings”

[Test this–> C:\>cd Doc (now press the tab button)].

If you have multiple files in the same folder, whose name starts with “D”, then you can navigate between them by pressing tab key multiple times.
cmd-text-completion-feature-UNIX-DOS
Many times we struggle to type the correct folder name and most of the times(when names are too long) end up typing wrongly. This can be avoided by knowing these simple yet powerful commands. Powerful because, we can use this feature with other commands to get some amazing results.

Unix:- Text Completion Feature

When you are in the command mode:-
Ex:-

$ar [tab]

In the above example, if a directory contains 4 folders or sub-directories by name 1. archive 2. archana 3. Sagar 4. archimedes, then you have to press the tab key two times, to get the list of all the sub-folders whose name starts with ar.

$ archive/ archana/ archimedes/

If there is only one sub-folder whose name starts with ar, then when you press the tab key once, the remaining letters of the word appears automatically.

In vi Editor:
When you are typing something in the vi editor, you can make use of this text completion feature. When you press [ctrl-p] after typing one or two letters, the text will auto complete. To autocomplete, Unix shell will look into the previously typed text in the same file and then fill the word accordingly. If there are more than one word which starts with the same letter(in the same file), then you can navigate between these words by using [Ctrl-n] option.

Some UNIX flavor does not support “Text-Completion-Feature”, and sh shall also does not support this feature. And some UNIX flavor may support this feature, but may have different keys to use.

Share your tips, tricks and hacks about commands in below comment section. By sharing our knowledge, we endup learning more..