View a range of bash history

Instead of history, you can use fc, which allow you select range:

fc -l 4 7

If you must use history command, pipe it through sed or awk:

history | sed -n '10,20p'

history | awk 'NR >= 10 && NR <= 20'

Otherwise cuonglm's answer is better option.

Using history with a grep on the line numbers around the command I'm looking for works best for me.

For instance I'm looking for what I did around ping mybox, more or less 20 lines.

$ history | grep "ping mybox" 20325 ping mybox

That's line 20325 so I just have to grep the lines starting by a number in the [20320..20339] range.

$ history | grep ^203[2-3][0-9]