I have two terminals open, both running zsh. The history options which I currently have set are these:

export HISTFILE=~/.histfile
export HISTSIZE=10000
export SAVEHIST=10000

When I type history, or fc -l, in either terminal, I see the last 16 commands (numbered). These histories are different in either shell, and are both different from what I see when I look inside .histfile.

As far as I can tell from the man zshoptions page, this is to be expected, and upon exiting the shell, its commands will be appended to the history.

In that case, where is each terminal's individual history stored until that point?

  • 1
    In memory, like all other shells.
    – cuonglm
    Sep 14, 2015 at 13:38
  • and drops it to history file only on logout / exit.
    – UVV
    Sep 14, 2015 at 13:42
  • Thanks - judging by stackoverflow.com/questions/7243983/… there is no other way to edit that history other than to logout/exit, then edit the newly saved lines in .histfile
    – SauceCode
    Sep 14, 2015 at 13:47

1 Answer 1


The INC_APPEND_HISTORY option, if set, causes a more immediate write of history entries. Also note SHARE_HISTORY, which if set may cause new shells to pick up on something it sounds like you want to remove from history. Rewriting the history live depends on these options, as if you do not care about other commands in that particular instance of the shell, and INC_APPEND_HISTORY is not set, simply clobber the history of that shell with fc -R:

% echo super secret password
super secret password
% echo whoopsie 
% history -2
18030  echo super secret password
18031  echo whoopsie
% history -3
36060  vim ~/.zshrc
36061  man readpassphrase
36062  mutt

And then confirm with $EDITOR $HISTFILE that that super secret password isn't in the history file (also! note that there may be a zshaddhistory function (or array of functions), in which case you'll need to inspect what that function (or those functions) does (do)). With INC_APPEND_HISTORY, the entry is probably in $HISTFILE, so editing the history file to remove the bad entry and then fc -R $HISTFILE should clear it from both the history file and the shell. With INC_APPEND_HISTORY and SHARE_HISTORY and if you suspect new shells have picked up that bad history entry, you'll need to do fc -R in all of those shells, or close them all, check that none have written the bad line back out to the history file, etc.

  • Thank you, this is becoming clearer. Before I had read anything, I had assumed , completely incorrectly, that the history file operated in the manner of SHARE_HISTORY. Can you point me to any documentation for fc -R? I can't find anything inside man fc. When I see the word 'clobber' I know I'd better read the docs first!
    – SauceCode
    Sep 14, 2015 at 15:11
  • 1
    man zshall | less -p '^[ ]*fc ' and then hit n a few times. (Or bindkey | grep run-help though I don't use that.)
    – thrig
    Sep 14, 2015 at 15:15
  • on OS X run-help opens the builtins man page instead of zshall
    – iconoclast
    Jul 17, 2017 at 15:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .