LinuxmacOS

Where Is Bash History Stored?

Bash HISTFILE paths on Linux and macOS, how HISTCONTROL and HISTSIZE shape it, and where zsh history differs on modern Macs.

Last updated

Bash appends each session to a history file in your home directory, usually ~/.bash_history. The HISTFILE variable can point elsewhere, and HISTSIZE plus HISTFILESIZE cap how much survives. Commands only flush on clean shell exit by default.

Modern Macs default to zsh, which uses ~/.zsh_history instead, so bash guides mislead there. Check echo $HISTFILE to print the live path before editing. Sensitive commands deserve HISTCONTROL=ignorespace plus manual cleanup rather than full file deletion. Logout traps with history appends flush commands mid session safely.

Where Bash stores this, by platform

Linux
~/.bash_history

Run echo $HISTFILE to confirm custom setups. Sessions in memory merge on exit, so close shells before copying the file for forensics.

macOS
~/.bash_history

Applies when running bash. The default zsh shell uses ~/.zsh_history instead. Check chsh -s output if history looks empty in the wrong file.

Frequently asked questions

How do I search bash history?

Press Ctrl+R for reverse search in the live shell, or grep ~/.bash_history for older sessions. The history command with a number shows the most recent entries first.

How do I delete a password from history?

Open ~/.bash_history, remove the offending lines, save, then run history -c and history -r to reload. Set HISTCONTROL to ignorespace so future secrets stay out.

Notice an outdated path? Let us know.