Aggiungere queste due righe in .bash_profile

bind '"e[A": history-search-backward'
bind '"e[B": history-search-forward'

In questo modo premendo up and down quando avete già digitato qualcosa sulla linea di comando, verranno mostrate solo le history che matchano

To obtain the key sequence from a function key, use the read command. The following is an example of pressing the [F12] key:

$ read

Note that different keyboards will produce different key sequences, and modifiers to the function keys (such as [Ctrl][F12] or [Shift][F12]) will produce other sequences as well.

The next step is to bind that key sequence to a particular shell command. For example, you can bind [F12] to the “history-search-backward” shell command:

$ bind '"e[24~": history-search-backward'

Make sure you write the key sequence as e[24~ rather than ^[[24~. This is because the ^[ sequence is equivalent to the [Esc] key, which is represented by e in the shell. So, for instance, if the key sequence was ^[[OP the resulting bind code to use would be e[OP.

Not only does the bind command bind function keys, but you can also use bind to map key sequences (such as [Esc][P] or [Esc][Q]) by writing the bind key code as ep and eq respectively.

For a list of shell commands that you can use, examine the /etc/inputrc file.