Display or manipulate the shell command history.
low risk
history lists previously executed commands with line numbers. You can re-run commands with !N (by number) or !! (last command). Ctrl+R provides interactive reverse search. HISTSIZE controls in-memory lines; HISTFILESIZE controls the history file.
| Flag | Meaning |
|---|---|
-c --clear | Clear all history (session) |
-d --delete | Delete a specific history entry by number |
-a --append | Append session history to history file |
-n --read-new | Read new lines from history file |
history 50Show last 50 commands · explain & risk-check →history | grep kubectlSearch history for kubectl commands · explain & risk-check →!42Re-execute command number 42 · explain & risk-check →history -d 42Delete command 42 from history · explain & risk-check →export HISTCONTROL=ignoredups:ignorespaceSkip duplicates and space-prefixed commands · explain & risk-check →Prefix any command with a space to exclude it from history — useful for commands containing passwords or tokens (requires HISTCONTROL=ignorespace).
Reference text is hand-written and may be incomplete — check man history for your version. Test destructive commands on a non-production system first.