How to get Bash shell history range
You can tell grep
to print some lines surrounding the match, e.g., 3 before and 5 after:
history | grep -B 3 -A 5 somecommand
grep -C 4
is equivalent to grep -A 4 -B 4
.
But often you won't know precisely how many lines you want in advance. So use less and search inside it. You can even launch the search from the command line:
history | less +/somecommand
Try fc:
fc -l 4972 5012
... it is a bash builtin command. (so don't try it in tcsh :>)
try history | grep -C20 '^4992'