How to 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.

To make working on the command line super easy for you, this is one of the many things you ought to do while performing:

  1. Initial Server Setup and Configurations on RHEL 7
  2. Initial Server Setup and Configurations on CentOS 7

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

Note: TAB 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.

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

Aaron Kili
Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

4 Comments

Leave a Reply
  1. Your examples of bash completion have nothing to do with the extra bash completion setup. Bash has built-in filename completion. Please someone review this article.

    Reply

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.