Typing Partial Commands Command Completion

Typing long commands or filenames can slow down command-line operations, both by adding to typing time and by increasing the odds of a typo, thereby causing a command to fail or have unintended consequences. Thus, bash and many other shells support a feature known as command completion. Type the first few letters of a command or filename and then press the Tab key. The shell locates all of the possible matching commands on the path or filenames that match. If just one command or filename matches, the shell fills out the rest of the command. If more than one command or filename matches, the shell beeps, displays all the matching names, or both, depending on the shell's configuration. If no files match the specified letters, the shell beeps.

For instance, at a command prompt, try typing chm and then the Tab key. The shell should respond by completing the command name: chmod. You can then enter a parameter for the command, making the text you see chmod 0644. If you then type a single letter for a filename and press Tab again, the shell may beep, display a list of files that begin with that letter, or fill in a complete filename.

You can configure whether the shell displays all of the matching filenames or simply beeps by adjusting the /etc/inputrc file. If you want bash to display a list of files, add the following line to inputrc:

set show-all-if-ambiguous on

If this feature is turned off, bash merely beeps when more than one file matches; pressing the Tab key again causes the display of matching files to appear.

0 0

Post a comment