Software & AppsOperating SystemLinux

How To Enable Command-Line Auto-Completion in Ubuntu 20.04

Ubuntu 19

In this guide, we will discuss how to enable command-line auto-completion in Ubuntu 20.04. This feature is incredibly useful, as it saves time and reduces the risk of errors by suggesting or completing commands based on what you’ve typed so far.

Quick Answer

To enable command-line auto-completion in Ubuntu 20.04, you can use the built-in features of the terminal such as tab completion, command history, and shortcuts like "!!" and "Ctrl" + "R". For enhanced auto-completion, you can install the "fzf" tool, which allows you to interactively search and select commands from your command history.

What is Command-Line Auto-Completion?

Command-line auto-completion is a feature that allows your terminal to suggest or complete commands as you type. This can be particularly useful when working with long or complex commands, or when you can’t remember the exact name of a command or file.

Enabling Auto-Completion

Tab Completion

The most basic form of auto-completion is Tab Completion. Simply start typing a command, then press the Tab key. If there is only one possible completion, it will be filled in automatically. If there are multiple options, pressing Tab twice will display a list of suggestions.

For example, if you type cd Do and press Tab, the terminal might auto-complete this to cd Documents/ if that’s the only directory in your current location starting with “Do”.

Command History

Another helpful feature is the Command History. You can use the up and down arrow keys to navigate through your command history. This allows you to quickly access and repeat previously executed commands.

For instance, pressing the up arrow will display the last command, and pressing it multiple times will cycle through previous commands. The down arrow will move forward in the command history.

Using “!!”

Typing !! and pressing Enter will execute the last command you ran. This is useful if you want to repeat a command quickly without typing it out again.

Using “Ctrl” + “R”

Pressing Ctrl + R allows you to search your command history using a reverse-i-search feature. Start typing a command or part of it, and the terminal will suggest matching commands from your history. Pressing Ctrl + R again will cycle through the matches, and pressing Enter will execute the selected command.

Installing fzf for Enhanced Auto-Completion

For an even more powerful auto-completion tool, you can install fzf, which is a command-line fuzzy finder. It allows you to interactively search and select commands from your command history.

To install fzf, you can run either sudo apt install fzf or git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf && ~/.fzf/install.

Once installed, you can use “Ctrl” + “R” to search your history and find matching commands. fzf will display a list of matching commands as you type, and you can use the arrow keys to navigate through this list and Enter to execute the selected command.

Conclusion

Command-line auto-completion is a powerful feature that can significantly speed up your workflow and reduce the risk of errors. By using the built-in features of the Ubuntu terminal and additional tools like fzf, you can quickly and easily access and execute commands, even if you can’t remember the exact syntax. Try it out and see how it can improve your command-line experience!

How do I enable command-line auto-completion in Ubuntu 20.04?

To enable command-line auto-completion in Ubuntu 20.04, you don’t need to do anything as it is already enabled by default. You can start using tab completion by typing a command and pressing the Tab key.

How does tab completion work?

Tab completion works by suggesting or completing commands based on what you’ve typed so far. When you press the Tab key, the terminal will automatically fill in the rest of the command if there is only one possible completion. If there are multiple options, pressing Tab twice will display a list of suggestions.

How can I navigate through my command history?

You can use the up and down arrow keys to navigate through your command history. Pressing the up arrow will display the last command, and pressing it multiple times will cycle through previous commands. The down arrow will move forward in the command history.

How can I quickly repeat the last command I ran?

To quickly repeat the last command you ran, you can simply type !! and press Enter. This will execute the last command without having to type it out again.

How can I search my command history?

You can search your command history using the Ctrl + R shortcut. Pressing Ctrl + R will activate the reverse-i-search feature, allowing you to start typing a command or part of it. The terminal will suggest matching commands from your history, and you can press Ctrl + R again to cycle through the matches. Pressing Enter will execute the selected command.

How can I install `fzf` for enhanced auto-completion?

To install fzf for enhanced auto-completion, you can run either sudo apt install fzf or git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf && ~/.fzf/install. Once installed, you can use Ctrl + R to search your history and find matching commands. fzf will display a list of matching commands as you type, and you can use the arrow keys to navigate through this list and Enter to execute the selected command.

Leave a Comment

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