image by erfouris studio from pixabay

Enable ‘Tab’ Key Bash Auto-Completion in Debian 12 ‘bookworm’

This simple tutorial shows how to enable bash completion feature in Debian 12 Stable ‘bookworm’.

Bash completion is a feather allows users to hit “Tab” key when working in command line, to auto-complete (or display available choices for) commands, options, file-names, etc.

This is a cool feature that saves lots of key presses. However, it may not function out-of-the-box, depends on which OS image you installed. And, this simple tutorial is going to show you how to enable it.

Step 1: Install bash-completion package

The bash completion feature is provided by the bash-completion package in most Linux. User need to first make sure that package is installed.

First, open “terminal” (konsole) from applications menu. When it opens, run command to install the package:

sudo apt install bash-completion

Run sudo apt update first to refresh cache, if it says ‘unable to locate package’.

Step 2: Configure bashrc file

After installed the bash-completion package, the function should work at next login.

If it’s still not working, open terminal and run command to edit the .bashrc file:

nano ~/.bashrc

When file opens in terminal/console, add following lines or make sure the following sections exist:

if ! shopt -oq posix; then
  if [ -f /usr/share/bash-completion/bash_completion ]; then
    . /usr/share/bash-completion/bash_completion
  elif [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
  fi
fi

Finally, save file by pressing Ctrl+X, typing y and hitting Enter. Also, log out and back in to apply change.

In addition, the ‘~/.bashrc’ only works for current users only. If you need to configure it for all users in the system, run sudo nano /etc/bash.bashrc command to configure the system-wide config file.

In addition

If the function is still not working after doing the previous steps, try looking into the config file under “/etc/bash_completion.d/” and “/usr/share/bash-completion” directories. There may be specific settings that hold the things back.

Hi, I'm Merilyn Ne, a computer geek working on Ubuntu Linux for many years and would like to write useful tips for beginners. Forgive me for language mistakes. I'm not a native speaker of English.