Zsh stores input lines (possibly with time information) in the file indicated by the variable
HISTFILE. This should be an absolute file name (otherwise it will be interpreted relative to whatever directory is current at the time).
Zsh has no built-in default value for
HISTFILE. The zsh distribution comes with a setup wizard for new users which has the value
~/.histfile built in, so this is what zsh users get by default. Oh-my-zsh comes with
HISTFILE=.zhistory preset. So it looks like you tried zsh both with the default setup and with oh-my-zsh. Check your
.zshrc (or the file dates) to see which one you’re currently using.
How zsh opens the file, and therefore what happens if it is a symbolic link, depends on several options.
- If one of the options
append_history(set by default),
share_historyis set, or when the history is saved explicitly with
fc -AI, zsh appends to the existing file.
Note that even under these settings, zsh occasionally overwrite the file as described below to trim it down to size.
- Otherwise, if the option
hist_save_by_copyis set (it’s set by default since zsh 5.0, but does not exist in 4.2), zsh writes a temporary file then moves it in place when complete. In this case, if the history file was a symbolic link, the new file replaces the symbolic link.
- Otherwise zsh overwrites the existing file in place.
Rather than point zsh to a symbolic link, set
HISTFILE to wherever you want the history file to be.
How many lines of history are kept is configured through the variables
HISTSIZE is the maximum number of lines that are kept in a session and
SAVEHIST is the maximum number of lines that are kept in the history file.
To get some history saved at all, you need to set both
SAVEHIST, as the default value of
SAVEHIST is 0. You may want to increase
HISTSIZE as well (as of zsh 5.0, the default is only 30).