Penguin

A time-saving tool is known as command completion, currently known as Tab Completion. If you type part of a file, command, or pathname and then press the [Tab] key, bash(1) will present you with either the remaining portion of the file/path, or a beep (if sound is enabled on your system). If you get a beep, just press [Tab] again to obtain a list of the files/paths that match what has been typed so far.

For example, if you forget the command updatedb, but remember a portion of the command, you can su to root, then at the shell prompt, type up, press the [Tab] key twice and you will see a list of possible completions, including updatedb and uptime. By typing the partial command "upd" and pressing [Tab] again, your command is completed for you.

bash(1)

You may need to source /etc/bash_completion before you get extra programmable completion features, if your system doesn't already source this for interactive shells.

zsh(1)

Zsh has a more powerful tab-completion mechanism than bash. This comes at the cost of slightly more processing and bloat, although these days you won't notice. To get the advanced shell function-based completion, you need to run the compinstall function once (which will set up your .zshrc file for future use).

Examples include:

$ ls -l
total 1
-rw-r--r--  1 me me  0 Jul 29 09:45 file1
-rwxr-xr-x  1 me me  0 Jul 29 09:45 file2*
$ chmod -x [TAB]

completing to only those files that currently have the +x permission set -- in this case, file2.

$ tar [TAB]
A  -- append to an archive
c  -- create a new archive
f  -- specify archive file or device
t  -- list archive contents
u  -- update archive
v  -- verbose output
x  -- extract files from an archive

tells you all the available options for this command (and what they do), based on any options you have already added. For tar, it will only complete files ending in ".gz" or ".bz2" if the -z or -j option is given, respectively.

See the zshcompsys ManPage for details on customising the completion rules.


You can enable limited tab-completion on Windows 2000 - see WindowsNotes.