Skip to content
shellmap

historyShow previously run commands from the shell history across all 5 shells

Equivalents in every shell

Bashunix
history

Builtin. Reads from `~/.bash_history` plus the in-memory list. `history N` shows the last N entries. Re-run by number with `!N`, or by prefix with `!prefix`.

Zshunix
history

Builtin. Default storage is `~/.zsh_history`. With `setopt EXTENDED_HISTORY`, entries are timestamped (`: <epoch>:0;<command>`). `fc -l` is the underlying primitive.

Fishunix
history

Fish stores history in a semi-structured YAML-like file at `~/.local/share/fish/fish_history`. `history search foo` greps interactively, `history delete --exact "rm -rf /"` removes a single entry.

PowerShellwindows
Get-History

Aliased as `history`, `h`, and `ghy`. Returns SESSION-ONLY history. For persistent cross-session history use the PSReadLine module: `Get-Content (Get-PSReadLineOption).HistorySavePath`.

cmd.exewindows
doskey /history

Cmd has no history file by default — `doskey /history` lists only the current session's commands. Press F7 for an interactive picker, or arrow keys for one-at-a-time recall. Nothing persists when the window closes.

Worked examples

Show the last 20 commands

Bash
history 20
Zsh
history -20
Fish
history | head -20
PowerShell
Get-History -Count 20
cmd.exe
doskey /history

Search history for a keyword

Bash
history | grep ssh
Fish
history search ssh
PowerShell
Get-History | Where-Object CommandLine -like "*ssh*"

Re-run a specific command from history by number

Bash
!42
Zsh
!42
PowerShell
Invoke-History 42

Gotchas

  • Bash writes history to `~/.bash_history` only on shell EXIT by default. Multiple terminals open at once race each other and overwrite — set `shopt -s histappend` and `PROMPT_COMMAND="history -a; $PROMPT_COMMAND"` for cross-terminal merging.
  • Zsh `~/.zsh_history` lines starting with `:` are timestamped (`: 1700000000:0;ls -la`). Tools that parse the file as plain commands must strip the prefix or filter for the `EXTENDED_HISTORY` format.
  • Fish history is multi-line and structured — do NOT edit the file by hand. Use `history delete` / `history merge` from inside fish to keep the index consistent; a hand-edit can corrupt the file.
  • PowerShell `Get-History` shows only the CURRENT SESSION. Cross-session history comes from PSReadLine, which writes to `(Get-PSReadLineOption).HistorySavePath`. Up-arrow recall is PSReadLine, NOT `Get-History`.
  • Cmd has no persistent history. Closing the window loses everything. For persistence, install PowerShell or a wrapper like Clink — vanilla cmd cannot do it on its own.

WSL & PowerShell Core notes

pwshPSReadLine ships with both Windows and Unix pwsh. The history file path differs: `~/AppData/Roaming/Microsoft/Windows/PowerShell/PSReadLine/ConsoleHost_history.txt` on Windows; `~/.local/share/powershell/PSReadLine/ConsoleHost_history.txt` on Linux/macOS. Use `(Get-PSReadLineOption).HistorySavePath` to read the resolved path on either OS.
WSLWSL bash history is per-distro and lives at `/home/$USER/.bash_history` inside the distro filesystem. It is NOT shared with Windows pwsh history; cross-shell search requires concatenating both files manually.

Related commands