Reputation: 81
Is there a way to do a "sub search" with ctrl-r. Say I want to search for "find" and then search in the results for something else. The search doesn't seem to be a regular expression in zsh at least, so something like "find.*foo" doesn't work.
Upvotes: 0
Views: 520
Reputation: 154911
In zsh you can use ESC x history-incremental-pattern-search-backward to search history for a pattern. Unfortunately the pattern is a glob-style pattern, not a regular expression.
Most terminal emulators will allow the use of Alt-X instead of ESC x.
Upvotes: 1
Reputation: 2713
I’m answering about bash
.
Neither reverse-search-history
(the function bound to Ctrl-r
), nor history expansion (by which you can re-invoke the last find
command typing !ls
, or print it typing !ls:p
) support globbing or regexes.
Your best option is
history | grep 'find.*foo'
to look for the regex 'find.*foo' in the the command history (you can also give, say, history 20
, to restrict the search to the last 20 commands in history).
Upvotes: 1