1

Enabling history to display time via export HISTTIMEFORMAT='%F %T ' shows the times of the commands but .bash_history doesn't contain any times.

Where does bash store the times the commands were executed?

Are they always stored automatically?

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
vfclists
  • 7,215
  • 14
  • 51
  • 79
  • I just checked via `history | less` and all the commands from some hours back use the same time, so it is probably storing the times only for the current session – vfclists Jan 03 '14 at 14:41
  • possible duplicate of [Finding command execution time in hindsight](http://unix.stackexchange.com/questions/44686/finding-command-execution-time-in-hindsight) – slm Jan 03 '14 at 15:29
  • 1
    @slm not a dupe, this one is asking where the information is stored, not how to get it. – terdon Jan 03 '14 at 22:46
  • @terdon - retracted, but still feels like a dup to me. The only new thing here is the `history -a` bit. – slm Jan 03 '14 at 22:55

1 Answers1

2

From the BASH_BUILTINS man page:

If the HISTTIMEFORMAT variable is set, the time stamp information associated with each history entry is written to the history file, marked with the history comment character. When the history file is read, lines beginning with the history comment character followed immediately by a digit are interpreted as timestamps for the previous history line.

So the information is stored in the history file only if HISTTIMEFORMAT is set.

(Try history -a to append the currently in-memory history entries to your history file. You should now see comments with unix timestamps in there.)

Mat
  • 51,578
  • 10
  • 158
  • 140