Bash – Search commands in history with discontinuous keywords

bashcommand historysearch

I was wondering how to search commands in history without knowing the first few letters of the command?

When searching using Ctrl+R in bash, one has to give the first few letters of the command. What if I only know some characters in the middle, or some at the beginning and some in the middle?

For example, to search cat myfile, I only know there is at in it, or c at the beginning and my in the middle somewhere. keywords have to be continuously positioned. For example, in cat myfile, I would like to search for bothc and my, but Ctrl+R will not allow to specify both simultaneously.

Best Answer

If you are just looking to find the line (to jog your memory) you could just grep for the part of the command you remember:

history | grep "substring"
Related Question