Enabling Bash Auto Completion on CentOS 7/8

Bash completion is a bash functionality that helps users type their commands faster and easier, by presenting possible options when the tab key is pressed while typing a command.

Bash auto-completion saves you time from typing text when it can be auto-completed, helps you to know the available continuations to a a specific command, and most importantly, prevents you from typing wrong commands as these are already completed for you.

Auto-completion isn’t a core feature of Bash, and as such, you might find some Linux installation lacking this functionality, especialy is you have opted for a minimal installation of Linux.

The steps below go through the installation of bash auto-completion in a CentOS 8 server with minimal installation.

The installation is very straight forward and is a two steps process. First, you need to install bash-completion script and the extra packages that come with it with dnf, then source the bash_completion.sh to add it to your ~/.bashrc file.

Install bash-completion along with its packages

$ sudo dnf install bash-completion bash-completion-extras -y
[sudo] password for mourad:
CentOS-8 - AppStream                      			1.6 kB/s | 4.3 kB     00:02
CentOS-8 - AppStream                      			383 kB/s | 6.3 MB     00:16
CentOS-8 - Base                           			1.3 kB/s | 3.9 kB     00:02
CentOS-8 - Base                           			499 kB/s | 7.9 MB     00:16
CentOS-8 - Extras                         			592  B/s | 1.5 kB     00:02

Source the bash_completion.sh script

$ source /etc/profile.d/bash_completion.sh

That’s it for this post, you will now be able to run commands with their auto-completion. To test the auto-completion feature, run any command then press TAB. Let’s do it with the yum command

$ yum gr<TAB>

$ yum group

$ yum group <TAB>

check-update  groupinfo     groupupdate   list          provides      search        whatprovides
clean         groupinstall  help          localinstall  remove        shell
deplist       grouplist     info          localupdate   repolist      update
erase         groupremove   install       makecache     resolvedep    upgrade

$ yum group li<TAB>

$ yum group list

Last metadata expiration check: 0:04:25 ago on Sat 16 Nov 2019 05:24:07 PM +04.
Available Environment Groups:
   Server with GUI
   Virtualization Host
   Custom Operating System
Installed Environment Groups:
   Minimal Install
Available Groups:
   Container Management
   .NET Core Development
   RPM Development Tools
   Smart Card Support
   Development Tools
   Graphical Administration Tools
   Headless Management
   Legacy UNIX Compatibility
   Network Servers
   Scientific Support
   Security Tools
   System Tools


1 Comment

  1. berndbausch

    It would help if you revealed which repo contains the bash-completion-extras package. On my server, yum list –enablerepo=* | grep bash-completion-extras reports nothing. I did enable the EPEL repos.


Leave a Comment

Your email address will not be published. Required fields are marked *