history — Show previously run commands from the shell history across all 5 shells
Equivalents in every shell
historyBuiltin. 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`.
historyBuiltin. Default storage is `~/.zsh_history`. With `setopt EXTENDED_HISTORY`, entries are timestamped (`: <epoch>:0;<command>`). `fc -l` is the underlying primitive.
historyFish 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.
Get-HistoryAliased as `history`, `h`, and `ghy`. Returns SESSION-ONLY history. For persistent cross-session history use the PSReadLine module: `Get-Content (Get-PSReadLineOption).HistorySavePath`.
doskey /historyCmd 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
history 20history -20history | head -20Get-History -Count 20doskey /historySearch history for a keyword
history | grep sshhistory search sshGet-History | Where-Object CommandLine -like "*ssh*"Re-run a specific command from history by number
!42!42Invoke-History 42Gotchas
- 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.