Install and Enable Bash Auto Completion in CentOS/RHEL

Bash (Bourne Again Shell) is undoubtedly the most popular Linux shell out there, no wonder it is the default shell on many Linux distributions. One of its most charming features is the built-in “auto-completion” support.

Sometimes referred to as TAB completion, this feature permits you to easily complete a command structure. It allows typing a partial command, then pressing the [Tab] key to auto-complete the command and it arguments. It lists all multiple completions, where possible.

Just like Bash, nearly all modern Linux shells ship in with command completion support. In this short guide, we will show you how to turn on the Bash auto-completion feature in CentOS and RHEL systems.

First, you need to enable the EPEL repository on your system, then install the bash-completion package plus some extras using YUM package manager, like this.

# yum install bash-completion bash-completion-extras

Now that you have installed bash completion, you should enable it to start working. First source the bash_completion.sh file. You can use the locate command below to find it:

$ locate bash_completion.sh
$ source /etc/profile.d/bash_completion.sh  
Find and Source Bash-Completion

Find and Source Bash-Completion

Alternatively, logout of your current login current session and re-login.

$ logout 

Now the auto-completion feature should be working on your system, you can try it out as shown below.

$ lo[TAB]
$ ls .bash[TAB]
Check Bash Auto-Completion

Check Bash Auto-Completion

NoteTAB completion works for path names and variables names as well, and it is programmable.

That’s all! In this guide, we showed how to install and enable the Bash auto-completion feature, also known as TAB completion in CentOS/RHEL. You can ask any questions via the comment section below.

source