Shell Command History – Best Way to Search Through Shell’s History

command historyshell

Is there a better way to search my history file for a command than grep? I do have some idea what the command starts as, but I don't know how far back in the history it is.

update: was formerly zsh specific but due to overlapping answers feel free to answer for any shell (or mode (vi/emacs)) here, just note if it is specific.

Best Answer

Ctrl+R is usually the best way, as descriptor said. You can also use !string, which runs the most recent command starting with string, or !?string?, which runs the most recent command that contains string.

(I think that's the only stuff relevant to this question, but I covered much more of the history commands in this answer)