Bash history between two points in time Bash history between two points in time shell shell

Bash history between two points in time


You could use sed. Say:

history | sed -n '2960,2966p'

to print line numbers 2960 to 2966 from the output of history command.

Quoting help history:

If the $HISTTIMEFORMAT variable is set and not null, its value is usedas a format string for strftime(3) to print the time stamp associatedwith each displayed history entry.  No time stamps are printed otherwise.

You could set the format to get the timestamp in the desired format by saying:

export HISTTIMEFORMAT="%F %T "

Since the history file is written by default only upon session close, you'd need to say:

history -w

in order to update the history file in the current session.


fc -l 2960 2966

This works on OS 10.6.X. It gives exactly what you need. Hope this helps!


try the following command . this will display the range from 2960 to 2966

fc -ln 2960-2966

to execute them you can try this

eval "$(fc -ln 2960 2966)"

Hope this helps.

Tharanga Abeyseela