About Me

I have decades of experience is software development using .Net Technologies, PHP and wordpress. I love coding and discovering new tech.

Blog

Fix Ubuntu Terminal Tab Completion Not Working (Easy Guide)

Server Management

Fix Ubuntu Terminal Tab Completion Not Working (Easy Guide)

Posted on April 23, 2024  - By Kaustav Halder - 0 Comments

Feeling frustrated with missing tab completion suggestions in your Ubuntu terminal? Don’t worry, this guide will walk you through a series of troubleshooting steps to get things back on track.

1. Install or Reinstall the bash-completion Package

Tab completion functionality heavily relies on the bash-completion package. If it’s missing, run:

sudo apt install bash-completion

If it’s already installed but malfunctioning, try reinstalling:

sudo apt install --reinstall bash-completion

2. Verify Shell and Permissions

Make sure you’re using Bash. Enter the below command in your terminal

echo $SHELL

A response of /bin/bash indicates Bash. If not, consider switching using the below command. You might have to follow the prompts to complete the change.

chsh -s /bin/bash

Next let’s also quickly check the permissions while we are at it. Enter the below command into the terminal.

ls -l /etc/bash_completion

Look for rw-r--r-- in the permissions column. If you lack read access, use the below command but be warned. Changing file permissions can be a risky and only do it at your own risk.

sudo chmod 644 /etc/bash_completion

3. Update Bash Configuration (.bashrc File):

This file controls Bash behavior. Open it for editing using your preferred text editor. So like me if you use nano, the command is as below to open file in edit mode.

sudo nano ~/.bashrc

Once the file is open, add the below code to the end of the file.

if ! shopt -oq posix; then
    if [ -f /etc/bash_completion ]; then
        . /etc/bash_completion
    fi
fi

Next we need to save the file so hit Ctrl + X. Then press Y and hit enter. So this tries to close the file and since the file is edited prompts to save file and exit. That’s exactly what we want to do. So we hit Y and enter.

4. Restart Your Terminal

For the modifications to take effect, relaunch your terminal.
Now, try a command and press Tab. If suggestions appear, you’ve successfully restored tab completion!

5. Still Not Working. Check BASH_COMPLETION_DIR environment variable is set.

To check the value of the variable, run the following command:

echo $BASH_COMPLETION_DIR

If the output of the command is not /etc/bash_completion, you need to set the variable to /etc/bash_completion. You can do this by running the following command:

export BASH_COMPLETION_DIR=/etc/bash_completion

Once done try step 4 again. Hopefully your issue should be solve.

Conclusion

Congratulations! With these solutions at your disposal, you should be well-equipped to tackle tab completion issues in your Ubuntu terminal. Remember, the command line is a powerful tool, and a well-functioning tab completion can significantly enhance your workflow. Now, go forth and conquer those command lines!pen_spark



About Kaustav

I have decades of experience is software development using .Net Technologies, PHP and wordpress. I love coding and discovering new tech.


0 Comments

Be the first to comment


Leave a reply

Leave a Reply

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