Use the ‘Up’ arrow key to search through the bash command history

You can enable the ‘Up’ arrow of your keyboard to search through commands that you have used in the past, on the terminal. Just type the initial few letters of the desired command and press ‘Up’ arrow, and you will get the commands that start with the letters you have typed.

To enable this search, you have to add the following lines at the end of your .bashrc file, which is stored in your home directory.




$bind ‘”e[A”: history-search-backward’
$bind ‘”e[B”:history –search-forward’

And them run thye following command:

$source _/.bashrc

For example, if your bash history contains the following:

python2.7 script.py
Perl script.pl
Php sample.php
Perl test.pl
Pytho2.7 sample.py
Python2.7 very_long_file_name.py

And if you want to search for a python2.7 command, then enter ‘py’ and press ‘Up’ arrow. The terminal will show commands that start with py, one at a time. You can keep pressing the ‘Up’ arrow to search until the terminal shows the desired command.

Leave a Reply

Your email address will not be published.