Linux Command Line Tips and Tricks

Jake G January 22, 2020 #Linux #Commandline

Aliases can be used to speed up your command line usage. They can be used to issue multiple commands with a single alias command.

The alias "update" is used to issue 3 commands apt-get update, apt-get dist-upgrade, and apt-get autoremove.

The alias "h()" is a function alias, this allows you to quickly search your history for keywords. such as "h nano" or "h grep" to get a list of lines from your bash history that match those keywords. We also ignore duplicates and lines beginning with a space and increase the history size.

The final alias is used for autocompletion of a line based on your bash history. You may already know that you can press the up key to go through previously exectuted commands, however with this alias you can type a partial command such as "sudo nano" and then press up, and it will scroll through only the lines in your history that started with "sudo nano". If you type to a point that you dont like the results, just press ctrl+c to get back to a clean prompt and start over.

echo "alias update='sudo apt-get update && sudo apt-get -y dist-upgrade && sudo apt-get autoremove'" >> ~/.bash_aliases && source ~/.bash_aliases

sed -i "s/HISTCONTROL=.*/HISTCONTROL=ignoreboth/" ~/.bashrc
sed -i "s/HISTSIZE=.*/HISTSIZE=9999/" ~/.bashrc
sed -i "s/HISTFILESIZE=.*/HISTFILESIZE=9999/" ~/.bashrc
echo 'h() {' >> ~/.bashrc && echo 'history | grep "$@"' >> ~/.bashrc && echo '}' >> ~/.bashrc

echo '"\e[A": history-search-backward' >> ~/.inputrc && echo '"\e[B": history-search-forward' >> ~/.inputrc && echo "set show-all-if-ambiguous on" >> ~/.inputrc && echo "set completion-ignore-case on" >> ~/.inputrc