Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

If commands disappear between terminal sessions, the cause is usually how history is saved, shared, filtered, or limited—not simply whether you use Bash or Zsh. Bash normally loads ~/.bash_history at startup and saves when the shell exits; Zsh gives you separate options for saving at exit, writing incrementally, and importing commands from other sessions.

Here is how those behaviors differ, how to configure them deliberately, and what to check when history has gaps.

How Bash and Zsh save history

Behavior Bash Zsh
History file HISTFILE defaults to ~/.bash_history. Bash reads it when an interactive shell starts and normally saves history when that shell exits. If HISTFILE is unset or null, Bash does not save history on exit. Automatic file persistence uses HISTFILE and SAVEHIST. HISTSIZE sets the number of commands kept in the in-memory history list; the Zsh guide describes reading that many lines at startup.
Concurrent sessions shopt -s histappend makes Bash append history on exit. Without it, the exiting shell can overwrite the file with its retained list, so one session may replace entries saved by another. APPEND_HISTORY appends when the shell saves. INC_APPEND_HISTORY writes entries incrementally. SHARE_HISTORY writes incrementally and imports new entries from the file into the current shell.
Search and recall Use the history and fc built-ins or Readline’s history search. Use history and fc or Zsh line-editor history search. fc -RI manually imports entries from the history file.
Time information HISTTIMEFORMAT enables timestamp storage and display for history entries. EXTENDED_HISTORY stores a command’s start time and elapsed duration.
Filtering and retention HISTCONTROL and HISTIGNORE can omit entries. HISTSIZE limits the in-memory list and HISTFILESIZE limits the history file. HIST_IGNORE_DUPS and HIST_IGNORE_SPACE can affect which entries are recorded. HISTSIZE and SAVEHIST govern in-memory and saved history limits.

The Bash behavior is described in the GNU Bash Reference Manual’s history facilities and its variable reference. Zsh’s settings are covered in the Z-Shell User’s Guide and the Zsh Manual, version 5.9.2, updated July 12, 2026.

Will history persist after you close a terminal?

Bash

For Bash, the usual sequence is: read the history file when an interactive shell starts, collect eligible commands during the session, then save at exit. The default file is ~/.bash_history. Check HISTFILE if nothing is being saved: an unset or empty value disables the normal exit save.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To make exit-time saves append rather than replace the file, enable the Bash shell option in an interactive startup file such as ~/.bashrc:

shopt -s histappend

Choose HISTSIZE and HISTFILESIZE to suit how much history you want retained in memory and on disk. These limits, and any filters, mean the file is not necessarily a complete record of every command you typed.

Zsh

For Zsh, configure HISTFILE, HISTSIZE, and SAVEHIST in your interactive configuration, commonly ~/.zshrc. The file setting identifies where history is stored; the size settings control the in-memory list and saved history limit.

Zsh separates when commands reach the file from whether one shell imports another shell’s entries. Select the behavior you need rather than treating the options as interchangeable.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How to make commands from other sessions visible

Bash: append at exit

With histappend enabled, each Bash session appends its retained entries when it exits instead of replacing the history file. This helps preserve entries from concurrent sessions, but the cited Bash documentation does not describe an option that imports another session’s commands live into the current one.

Zsh: choose one write and import strategy

  • APPEND_HISTORY: append commands when the shell saves history.
  • INC_APPEND_HISTORY: write each eligible command to the history file incrementally as it is entered.
  • SHARE_HISTORY: write incrementally and import new commands from the history file into the current shell.

The current Zsh manual says INC_APPEND_HISTORY, INC_APPEND_HISTORY_TIME, and SHARE_HISTORY are mutually exclusive choices. In particular, it says to turn off INC_APPEND_HISTORY when SHARE_HISTORY is in effect. If you prefer sharing only when you choose, keep automatic sharing disabled and import with fc -RI.

“Sharing” here means shells reading and writing a history file, typically on the same host or through a shared home directory. It is not cloud synchronization.

How to search and use older commands

Both shells provide the history and fc built-ins, as well as interactive history search through their line-editing facilities. These are ways to inspect or recall entries that were recorded; they cannot recover commands that were filtered out, fell outside retention limits, or never reached the file.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

In Zsh, fc -RI imports entries from the history file into the current shell when you want a controlled import instead of automatic sharing. Bash’s cited documentation describes history and Readline search, but not a corresponding live import of commands from another session.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Why history can have gaps

A history file is a filtered, size-limited convenience record, not necessarily an audit log. Check the relevant controls before assuming that commands have been deleted:

  • File path and write access: confirm HISTFILE points to the expected writable file. In Bash, an unset or null value prevents saving on exit.
  • Shell and history state: confirm the shell is interactive and history is enabled.
  • Filters: Bash’s HISTCONTROL and HISTIGNORE, or Zsh’s ignore and duplicate options, may intentionally omit commands.
  • Retention limits: inspect Bash’s HISTSIZE and HISTFILESIZE, or Zsh’s HISTSIZE and SAVEHIST.
  • Concurrent Bash sessions: check whether histappend is enabled if several shells use the same history file.
  • Zsh sharing mode: distinguish appending at save time from incremental writing and importing; only SHARE_HISTORY combines incremental writes with imports.
  • Metadata and multiline entries: if timestamps or commands spanning multiple lines matter, check the relevant format option before interpreting the file as plain one-command-per-line text.

These are checks of documented behavior, not a diagnosis of any particular missing-history problem. For example, someone might find old commands and recent commands but not entries between them; that pattern alone does not identify whether filtering, limits, session writes, or another setting is responsible.

Timestamps and file compatibility

Bash’s HISTTIMEFORMAT causes timestamps to be saved and displayed. Zsh’s EXTENDED_HISTORY adds a command’s start time and elapsed duration. These formats and meanings differ, so do not assume that a history file moved between shells will retain all metadata or behave identically in both.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The GNU online Bash reference pages cited here do not establish a specific Bash release version. The Zsh manual cited here identifies itself as version 5.9.2 and was updated July 12, 2026.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.