Where does zsh store timestamps and execution times

On macOS I am using these options in my .zshrc file related to command-line history:

# History is appended after completion of each command and with extended information: timestamp and duration.
# This means the history is saved in chronological order (of command completion time).
# However, the history is not shared, so each terminal has its own history while it is open.
setopt INC_APPEND_HISTORY_TIME

# Keep more entries in memory and in .zsh_history file.
HISTSIZE=10000
SAVEHIST=5000

# When trimming history file, keep unique commands and trim duplicates first.
setopt HIST_EXPIRE_DUPS_FIRST

# Do not enter a command into the history if it is a duplicate of the previous event.
setopt HIST_IGNORE_DUPS

This works perfectly and if I run these two commands…

% sleep 1
% sleep 2

…I can now see the time of execution as well as the time spent in the history:

% history -DE -2
 5056  21.11.2020 23:13  0:01  sleep 1
 5057  21.11.2020 23:14  0:02  sleep 2

However, looking at the .zsh_history file reveals only the command with no trace of the timestamps and execution times.

% tail -3 .zsh_history
sleep 1
sleep 2
history -DE -2

Sending it through hexdump -C reveals no secret characters:

% tail -4 .zsh_history | hexdump -C
00000000  73 6c 65 65 70 20 31 0a  73 6c 65 65 70 20 32 0a  |sleep 1.sleep 2.|
00000010  68 69 73 74 6f 72 79 20  2d 44 45 20 2d 32 0a 74  |history -DE -2.t|
00000020  61 69 6c 20 2d 33 20 2e  7a 73 68 5f 68 69 73 74  |ail -3 .zsh_hist|
00000030  6f 72 79 0a                                       |ory.|
00000034

Does someone know where zsh stores that information?

Asked By: mgd

||

It doesn’t store this info anywhere, except in memory. At least, not unless you also add

setopt EXTENDED_HISTORY

to your ~/.zshrc file. Then it will write them permanently to your $HISTFILE.

(setopt SHARE_HISTORY also writes this info to your $HISTFILE, but only temporarily. It will remove all time info from your $HISTFILE when you exit the shell.)

Answered By: Marlon Richert
Categories: Answers Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.