Auto-complete And View Previous Commands (history) in The Terminal
This article could be helpful for those new to Linux who find the terminal confusing or complex. Previously typed commands are stored up to 500 lines and can be increased in the .bash_profile.
Here are some ways to make command writing in the Linux terminal easier:
1. Using History
View previous commands in the terminal by pressing the up arrow key on the keyboard. Just press Enter after finding the previous command. This helps speed up command writing. However, it can be cumbersome if there are over 100 history entries and the desired command is in the middle or beginning. You can use the command:
history
This will display a list of previously used commands.
2. Using "reverse-i-search"
To see the next matching command, press CTRL+R again. For example, if you've typed sudo apt install and sudo apt upgrade before and you use "reverse-i-search" with the keyword apt, if the first result is sudo apt install, pressing CTRL+R again will show sudo apt upgrade.
3. Using OhMyZsh and the zsh-autosuggestions plugin
curl | sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" |
wget | sh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" |
fetch | sh -c "$(fetch -o - https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" |
If you encounter the issue "Zsh not installed. Please install zsh first" as shown in the image below, install Zsh first.
Here’s how to install Zsh:
sudo apt install zsh
Then, check if Zsh is installed by running:
zsh --version
The version of Zsh will appear.
If there are any updates for the installation and more detailed instructions, you can check the developer's GitHub through the following link: https://github.com/ohmyzsh/ohmyzsh#basic-installation.
Secondly, add the zsh-autosuggestions plugin using the complete instructions on GitHub: https://github.com/zsh-users/zsh-autosuggestions/blob/master/INSTALL.md#oh-my-zsh.
And here’s how it looks.
Here's an example of autocomplete when typing the command "cd D":https://towardsdev.com/3-simple-ways-to-set-up-autocompletion-in-the-terminal-cf4915d29281