Quite often I grep
through my bash shell history to find old commands, filepaths, etc. Having identified the history number of interest, I would like to see a few lines of context on either side, i.e. view a subset of history lines. For example:
$ history | grep ifconfig
8408 ifconfig eth0
8572 sudo ifconfig eth0 down
I would like to look at the 5 lines or so either side of line 8572. Obviously knowing the line number I can page through the history with less
, but this seems very stupid. As far as I can tell, the manpage doesn't seem to have this information either.
Is there a simple way to retrieve arbitrary lines of history in bash?