macOSLinux

Where Is Zsh History Stored?

Where zsh keeps command history on macOS and Linux, which variables control it, and how it differs from bash.

Last updated

Zsh appends commands to ~/.zsh_history in your home directory on both macOS and Linux. Three variables shape it: HISTFILE sets the path, HISTSIZE caps session memory, SAVEHIST caps what gets written to disk. Run echo $HISTFILE to print the live file before editing anything.

Bash refugees trip on two differences. The filename starts with z, and zsh skips duplicate or space prefixed commands only when the matching hist options are set. Sizing SAVEHIST below HISTSIZE silently truncates history on every exit, which looks exactly like data loss.

Where Zsh stores this, by platform

macOS
~/.zsh_history

Default shell since Catalina, so this is the file Mac terminal users want, not ~/.bash_history. Control size with HISTSIZE and SAVEHIST in ~/.zshrc, then reload the shell.

Linux
~/.zsh_history

Same file and variables as macOS. Check echo $HISTFILE first: distros and frameworks like oh-my-zsh can relocate it. Commands flush on clean exit unless INC_APPEND_HISTORY is set.

Frequently asked questions

I followed a bash history guide on my Mac and the file is empty. Why?

Probably. macOS switched the default shell to zsh in Catalina, so guides pointing at ~/.bash_history send Mac users to a file their shell never writes. Run echo $SHELL and echo $HISTFILE to see which shell and file are actually live.

My recent zsh commands vanish after a crash. How do I stop that?

Add setopt INC_APPEND_HISTORY (write each command immediately) or SHARE_HISTORY (share live between sessions) to ~/.zshrc. By default zsh only flushes on clean exit, so a crashed terminal loses its tail.

Notice an outdated path? Let us know.