Frequently Asked Question
How does tab completion work?
Pressing Tab asks the shell to finish what you've started typing. With no extra
configuration, bash completes command names by searching PATH, and file and
directory names by listing what's in the relevant directory. cd ~/Doc<Tab>
expands to cd ~/Documents/; git che<Tab> expands to git checkout if git is
the only matching command.
Beyond the defaults, bash has a programmable completion system: the
bash-completion package, shipped with most distributions, registers completion
functions for hundreds of commands. With it installed, git che<Tab> completes
sub-commands, systemctl restart ngi<Tab> completes unit names, apt install libssl<Tab> completes package names. Internally each completion is a shell
function registered with the complete builtin; you can write your own with
complete -F mycomplete mycommand. Zsh and fish ship with much more aggressive
completion out of the box, fish in particular reads completions straight from
man pages.