ArticleslgStudy

science

Command-line completion

Command-line completion is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Command-line completion rather than just read about it. In short: Command-line completion (also tab completion) is a common feature of command-line interpreters, in which the program automatically fills in partially typed commands. Command line interpreters are programs that allow a user to interact with the underlying operating system by typing commands at a command prompt using a command line interface (CLI), in contrast to pointing and clicking a mouse in a graphical user inter…

Command-line completion — main illustration
Command-line completion — illustration

Key takeaways

  • Command-line completion belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Command-line completion to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Command-line completion from memory before moving on to harder problems.

Reference excerpt

Command-line completion (also tab completion) is a common feature of command-line interpreters, in which the program automatically fills in partially typed commands. Command line interpreters are programs that allow a user to interact with the underlying operating system by typing commands at a command prompt using a command line interface (CLI), in contrast to pointing and clicking a mouse in a graphical user interface (GUI). Command-line completion allows the user to type the first few characters of a command, program, or filename, and press a completion key (normally Tab ↹) to fill in the rest of the item. The user then presses Return or ↵ Enter to run the command or open the file. Command-line completion is useful in several ways, as illustrated by the animation accompanying this article. Commonly accessed commands, especially ones with long names, require fewer keystrokes to reach. Commands with long or difficult to spell filenames can be entered by typing the first few characters and pressing a completion key, which completes the command or filename. In the case of multiple possible completions, some command-line interpreters, especially Unix shells, will list all possible completions beginning with those few characters. The user can type more characters and press Tab ↹ again to see a new, narrowed-down list if the typed characters are still ambiguous, or else complete the command/filename with a trailing space. An alternate form of completion rotates through all matching results when the input is ambiguous. Completable elements may include commands, arguments, file names and other entities, depending on the specific interpreter and its configuration. Command-line completion generally only works in interactive mode. That is, it cannot be invoked to complete partially typed commands in scripts or batch files, even if the completion is unambiguous. The name tab completion comes from the fact that command-line completion is often invoked by pressing the tab key.

History Tab completion appeared in the early 1960s. The French SEA CAB 500 computer (ca. 1960) included an interactive language, PAF (Programmation Automatique de Formules), which provided command completion. The command line of the Berkeley Timesharing System for the SDS 940 (ca. 1964) supported completion: if a typed command or filename was unambiguous, the interpreter would complete it without any user command; if the string was ambiguous, it did nothing. This meant that if the user typed more than the minimal prefix, the additional characters would be interpreted as part of the next input token, which is not what the user intended. The TENEX operating system (ca. 1969) adopted the idea as escape completion, requiring the user to invoke autocompletion explicitly by typing escape. The TENEX descendant TOPS-20 offered command line completion by 1977 as a system call, COMND JSYS, making it available to all applications. Completion was added to Unix's tcsh command shell in 1981.

Example To open the file introduction-to-command-line-completion.html with Firefox one would type:

firefox introduction-to-command-line-completion.html

This is a long command to type. Instead we can use command-line completion.

Prompting completion The following example shows how command-line completion works in Bash. Other command line shells may perform slightly differently. First we type the first three letters of our command:

fir

Then we press Tab ↹ and because the only command in our system that starts with "fir" is "firefox", it will be completed to:

firefox

Then we start typing the file name:

firefox i

But this time introduction-to-command-line-completion.html is not the only file in the current directory that starts with "i". The directory also contains files introduction-to-bash.html and introduction-to-firefox.html. The system can't decide which of these filenames we wanted to type, but it does know that the file must begin with "introduction-to-", so the command will be completed to:

firefox introduction-to-

Now we type "c":

firefox introduction-to-c

After pressing Tab ↹ it will be completed to the whole filename:

firefox introduction-to-command-line-completion.html

In short we typed:

firTab ↹iTab ↹cTab ↹

This is just eight keystrokes, which is considerably less than 52 keystrokes we would have needed to type without using command-line completion.

Rotating completion The following example shows how command-line completion works with rotating completion, such as Windows's CMD uses. We follow the same procedure as for prompting completion until we have:

firefox i

We press Tab ↹ once, with the result:

firefox introduction-to-bash.html

We press Tab ↹ again, getting:

firefox introduction-to-command-line-completion.html

In short we typed:

firTab ↹iTab ↹Tab ↹

This is just seven keystrokes, comparable to prompting-style completion. This works best if we know what possibilities the interpreter will rotate through.

… excerpt ends here. Continue reading the full article.

Illustrations

Command-line completion: Example of command-line completion in PowerShell with Intellisense.
Example of command-line completion in PowerShell with Intellisense.

Worked examples

Example 1 — a first encounter with Command-line completion

Start with the simplest possible case. Write down what Command-line completion claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Command-line completion before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Command-line completion ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Command-line completion

In research
Command-line completion appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Command-line completion in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Command-line completion is common in secondary-school and first-year university syllabi. It links to neighbouring topics Autocomplete, User interface techniques, so understanding it makes those chapters shorter.
In everyday life
Look for Command-line completion outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Command-line completion” →

How to study Command-line completion in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Command-line completion means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Command-line completion out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Command-line completion in simple terms?

Command-line completion (also tab completion) is a common feature of command-line interpreters, in which the program automatically fills in partially typed commands. Command line interpreters are programs that allow a user to interact with the underlying operating system by typing commands at a com…

Why does Command-line completion matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Command-line completion?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Command-line completion.

Tags

  • Autocomplete
  • User interface techniques

Keep exploring