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?

  • 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 3 '14 at 14:41
  • possible duplicate of Finding command execution time in hindsight – slm Jan 3 '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 3 '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 3 '14 at 22:55

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.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.