1

Somehow my zsh history shows wrong timestamps like this.

❯ history -E 1 | tail -20 6047 31.12.2019 15:08 babel-node 6048 31.12.2019 15:08 node -v 6049 31.12.2019 15:08 git diff 6050 31.12.2019 15:08 rm package-lock.json 6051 31.12.2019 15:08 yarn update 6052 31.12.2019 15:08 yarn 6053 31.12.2019 15:08 rm yarn.lock 6054 31.12.2019 15:08 yarn install 6055 31.12.2019 15:08 yarn serve 6056 31.12.2019 15:08 exit 6058 31.12.2019 15:00 bin/rails s 6059 31.12.2019 15:00 cd ../my_project 6060 31.12.2019 15:00 bin/rails c 6062 31.12.2019 15:03 man history 6063 31.12.2019 15:03 vi ~/.bash_history 6064 31.12.2019 15:03 vi ~/.zsh_history 6065 31.12.2019 15:04 zsh -f 6066 31.12.2019 15:06 fc -li 100 6067 31.12.2019 15:08 history -E 1 | tail -100 

All command those timesstamps 15:08 except the latest history command are executed before yesterday. The timestamps for old commands refresh every time history command is executed.

Though I'm going to clear history data, I don't want to encounter the same bug. Does anyone know what causes this error and how to prevent it?

I'm using zsh 5.3 (x86_64-apple-darwin18.0) in iTerm2.

variables

These are my hist related variables.

❯ env | grep HIST ❯ typeset | grep HIST HISTCHARS='!^#' integer 10 readonly HISTCMD=6119 HISTFILE=/Users/ironsand/.zsh_history integer 10 HISTSIZE=10000 integer 10 SAVEHIST=10000 
2
  • What *HIST* variables (and related options) have you set in your shell, and to what values? Commented Dec 31, 2019 at 7:45
  • 1
    I added variables probably related to history command. Commented Jan 6, 2020 at 12:13

1 Answer 1

4

If you don't have the EXTENDED_HISTORY shell option set in zsh, then the history events that are saved to $HISTFILE will be saved without timestamps.

When you use history -E 1, the history events are printed from the start of the in-memory history to the end, with timestamps (formatted in a particular way).

History entries that were read from $HISTFILE don't have timestamps, so they are assigned the timestamp corresponding to the time when the history command was executed.

To save timestamps with each history event, enable the EXTENDED_HISTORY shell option. To do this for all future interactive zsh shell session, modify your $ZDOTDIR/.zshrc file and add

setopt EXTENDED_HISTORY 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.