How to search all matching previous commands using ctrl+R in Linux How to search all matching previous commands using ctrl+R in Linux unix unix

How to search all matching previous commands using ctrl+R in Linux


If you press Ctrl+R and type your search, you will get the last record matching this search.

If you press Ctrl+R again you will get the previous record. You can press Ctlr+R repetitively to get older matches.

This doesn't provide a list though.


Not sure if you can do this using Ctrl+R, but you can leverage history command and achieve similar result:

man history:NAME       history - GNU History Library

Add a function to your ~/.bashrc that checks a history.

For example:

h() { history | grep "$1" | grep "$2" | grep "$3" | head -10 | sed 's/[^ ]*  //'; }

Then you would need to copy and paste the result. ( You may also need to adjust sed command to strip out number and spaces more accuratly)