Pcornel
Browse topics
Options
Recent
Favorites
Linux · Technical reference

Bash History

Direct answer

Bash history records the commands you type, stored in ~/.bash_history when the shell exits. history lists them; !n, !! and Ctrl+R recall them.

When to use this

Use it to find what was run, repeat commands, or when history is missing or contains secrets.

First 30 seconds

1. history | tail — recent commands.

2. Missing from another session → not written yet; history -a writes now.

3. Lost between sessions → shopt -s histappend in ~/.bashrc.

4. Secret in history → history -d <n> and history -w.

5. Size: HISTSIZE / HISTFILESIZE.

Operational verification

command typed → kept in memory → appended/written to ~/.bash_history on exit (or history -a) → available to new shells

Evidence · next step

For Shell & Bash → Bash History, continue with the first unproven Topic check: Record current shell/session and history configuration: HISTFILE, HISTSIZE, HISTFILESIZE, HISTCONTROL/HISTIGNORE and append settings. If that boundary is healthy, advance to the adjacent check: Differentiate in-memory history from persisted file and flush/read deliberately only when safe. Preserve the same host/time/identity scope and rerun the original workload before accepting recovery.

Continue only after interpreting the current observation.
Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
linux
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

Platformlinux
Scope / prerequisiteUse it to find what was run, repeat commands, or when history is missing or contains secrets.
What next?3 suggested next steps
Evidence1
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

5 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

Capture the concrete output, symptom, packet, log or counter before changing anything.

Step 1 Operational evidence path Verify boundary

interactive parsed command → history admission/filtering → in-memory list → optional timestamps → session flush/append/write → HISTFILE → later recall/forensic correlation

Healthy evidence: history settings and session persistence are understood, relevant entries are correlated with independent evidence and secrets are handled as exposures.

Step 2 Verification and output interpretation Verify boundary

Existing fast checks for this Topic. - Record current shell/session and history configuration: HISTFILE, HISTSIZE, HISTFILESIZE, HISTCONTROL/HISTIGNORE and append settings.

  • Differentiate in-memory history from persisted file and flush/read deliberately only when safe.
  • Correlate suspected commands with audit logs, sudo logs, journal, process/application evidence and filesystem state.
  • Treat secrets found in history as exposed credentials and rotate/revoke them rather than merely editing history.

Verification chain. interactive parsed command → history admission/filtering → in-memory list → optional timestamps → session flush/append/write → HISTFILE → later recall/forensic correlation

Step 3 Commands Verify boundary
history | tail
HISTCONTROL=ignorespace
 export TOKEN=...   # leading space skips history
Step 4 Failure modes and next checks Narrow the fault

Suspicious evidence: operators rely on history as forensic truth, concurrent sessions overwrite chronology, filtering hides commands, or credentials remain valid after history cleanup.

Step 5 Common mistakes Narrow the fault
  • Secrets typed on the command line ending up in history.
Evidence references

Evidence · 1 on this Topic

Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.

observation · 1
Key points

Each shell writes its history on exit, so parallel sessions overwrite each other unless shopt -s histappend is set. Commands starting with a space are not saved when HISTCONTROL=ignorespace. Never type passwords on the command line; if you did, remove the entry (history -d <n>).

Key checks
  • history | tail — recent commands
  • bash -x script.sh — trace each expanded command
  • bash -n script.sh — syntax check only
  • shellcheck script.sh — common bugs and quoting problems
  • echo $? — exit code of the last command
ReferenceWhat it is1 section · depth on demand

Core model

Distinguish current shell history from persisted HISTFILE content. Multiple concurrent shells can overwrite/append differently; HISTCONTROL/HISTIGNORE can suppress entries; timestamps require HISTTIMEFORMAT for display and stored epoch markers; sensitive data may have been written despite later deletion.

ReferenceImportant terms & boundaries5 sections · depth on demand

What this shows and what it does not

Bash history is convenience/lead evidence, not an authoritative audit trail; command presence/absence cannot independently show execution or outcome.

Logging/Security/Auditd own authoritative audit evidence; .bashrc/.profile can configure history; this Topic owns Bash history behavior and limitations.

In depth

Bash history: storage, control and reuse

Bash keeps a list of the commands you've typed and saves it to a file when the shell exits. The bash(1) manual page documents the variables that control it:

  • HISTFILE defaults to ~/.bash_history. If it's unset or empty, history isn't saved.
  • HISTSIZE (default 500) limits the entries kept in memory, and HISTFILESIZE limits the lines kept in the file.
  • HISTCONTROL accepts ignorespace, ignoredups, ignoreboth and erasedups.
  • HISTIGNORE is a colon-separated list of patterns that aren't saved.
  • HISTTIMEFORMAT adds timestamps.

A practical configuration

SettingEffect
HISTSIZE=50000, HISTFILESIZE=100000Much longer history
HISTCONTROL=ignorebothSkip duplicates and lines starting with a space
HISTTIMEFORMAT='%F %T 'Show when each command ran
shopt -s histappendAppend instead of overwrite when several shells exit
PROMPT_COMMAND='history -a'Write each command immediately

Reusing commands

ShortcutMeaning
Ctrl-RReverse incremental search
!!The previous command (sudo !!)
!$The last argument of the previous command
!n / !-nCommand number n / n commands back
^old^newRepeat the previous command with a substitution
history | grep sshSearch the list
fcEdit the previous command in an editor

Secrets

With ignorespace, a command that starts with a space isn't saved. That's useful for one-off commands containing a token, but better tools exist. Read secrets with read -s, or keep them in a file or a password manager.

host$ cat >> ~/.bashrc <<'EOF'
HISTSIZE=50000
HISTFILESIZE=100000
HISTCONTROL=ignoreboth
HISTTIMEFORMAT='%F %T '
shopt -s histappend
PROMPT_COMMAND="history -a${PROMPT_COMMAND:+; $PROMPT_COMMAND}"
EOF
host$ source ~/.bashrc
host$ history 3
  1042  2026-11-28 11:20:01 systemctl status nginx
  1043  2026-11-28 11:20:09 journalctl -u nginx -n 50
  1044  2026-11-28 11:20:15 history 3
host$ systemctl restart nginx
Failed to restart nginx.service: Access denied
host$ sudo !!
sudo systemctl restart nginx
host$  read -rs -p "Token: " TOKEN; echo

History isn't an audit log

Users can edit or delete their own history. For accountability, rely on sudo logging, auditd or session recording. Treat ~/.bash_history as a convenience only.

Documented example, not captured output.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.

How it works at runtime

Bash History is part of Shell & Bash → Bash History. Bash History records selected interactive command lines for recall, but history files, in-memory session state, timestamps and filtering rules make it an incomplete and mutable operational record.

Topic-specific state model. Bash History records selected interactive command lines for recall, but history files, in-memory session state, timestamps and filtering rules make it an incomplete and mutable operational record.

Interpretation rule. - History entry ≠ evidence the command executed successfully or at all.

  • No history entry ≠ command was not run.
  • History file order ≠ strict cross-session chronology under concurrent shells.
  • Deleting a history line ≠ secret exposure is remediated in logs, process lists, audit systems or backups.

Quick reference

Bash history settings (~/.bashrc or /etc/profile.d/):

HISTSIZE=10000
HISTFILESIZE=20000
HISTTIMEFORMAT='%F %T '
HISTCONTROL=ignoreboth          # ignore duplicates and lines starting with space
shopt -s histappend
PROMPT_COMMAND='history -a'      # write each command immediately

Useful: Ctrl+R reverse search, !! last command, !$ last argument, history | grep ssh. Shell history is not an audit log (users can edit or disable it) — use auditd or session recording for accountability. Commands with secrets: start with a space (ignorespace) or read secrets from files.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.

Limits and how it fails

Primary failure point. Bash history is convenience/lead evidence, not an authoritative audit trail; command presence/absence cannot independently show execution or outcome.

ReferenceConfiguration & state1 section · depth on demand

Configuration, persistence and lifecycle

Distribution/platform context. Logging/Security/Auditd own authoritative audit evidence; .bashrc/.profile can configure history; this Topic owns Bash history behavior and limitations.

Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Technical verification history

Verification history & basis

When and against what this Topic was checked. Later text edits do not count as a new check.

2026-09-14 · vendor doclinux current

Authoritative/upstream documentation reviewed for bounded claims in Shell & Bash → Bash History. Documentation verification only; this is not observed lab or production Evidence.

Basis: https://www.gnu.org/software/bash/manual/bash.html · confidence 94%
Technical changelog & impact

What changed and what may be affected

Recent technical edits are separated from ordinary page timestamps. Relationship impact is advisory: it identifies nearby canonical references to review, not automatic breakage.

Related reference impactReview these references after material technical changes when their shared boundary is affected.
Terminology layer

Terms & aliases

Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.

Aliases that resolve here
bash historyHISTFILEbash command historyHISTCONTROL
Embedded reference data

Quick lookup tables

Bash History operational reference

Topic-specific lookup boundaries, proof limits and next-step Evidence for Bash History.

Lookup boundaryTopic-specific referenceOperational use
Scope / effective stateBash History records selected interactive command lines for recall, but history files, in-memory session state, timestamps and filtering rules make it an incomplete and mutable operational record.Establish exactly what this Topic owns before crossing into another subsystem.
Fast verificationPin host/distribution + shell/version/mode → identify cwd/mount namespace + input/path/stream → preserve quoting/expansion and final argv → map fd/pipeline/process boundaries → inspect object/variable/status/signal state → make one minimal reversible change → read back effective state → repeat original consumer/script/workload test.Use the shortest evidence path first; a fast check is a boundary test, not blanket proof.
Verification chaininteractive parsed command → history admission/filtering → in-memory list → optional timestamps → session flush/append/write → HISTFILE → later recall/forensic correlationTrace requested/configured state through effective state to the observed workload result.
Failure boundaryBash history is convenience/lead evidence, not an authoritative audit trail; command presence/absence cannot independently prove execution or outcome.Stop broad troubleshooting at the first boundary that is not supported by evidence.
Positive evidenceCorrelated Linux file/text/shell evidence can establish this proof path: interactive parsed command → history admission/filtering → in-memory list → optional timestamps → session flush/append/write → HISTFILE → later recall/forensic correlationUse this observation only for the specific claim it actually supports.
Evidence limitIt does not independently prove behavior outside the captured host, shell/session, cwd/namespace, input, process, filesystem, locale, time or workload scope. Bash history is convenience/lead evidence, not an authoritative audit trail; command presence/absence cannot independently prove execution or outcome.Do not promote a local success signal into end-to-end or adjacent-dependency proof.
Next troubleshooting checkContinue from the first unproven boundary: capture the exact shell-delivered argv/streams or resolved object, verify the effective target state, change only the demonstrated cause, then repeat the original consumer/script/workload and adjacent regression checks.Continue to the next unresolved boundary while preserving the original test condition.

Bash History · operational reference

Compact Linux state, persistence, verification and boundary reference for fast lookup.

Reference boundaryBash History
Topic pathShell & Bash → Bash History
Runtime stateBash History records selected interactive command lines for recall, but history files, in-memory session state, timestamps and filtering rules make it an incomplete and mutable operational record.
Fast checks- Record current shell/session and history configuration: HISTFILE, HISTSIZE, HISTFILESIZE, HISTCONTROL/HISTIGNORE and append settings. - Differentiate in-memory history from persisted file and flush/read deliberately only when safe. - Correlate suspected commands with audit logs, sudo logs, journal, process/application evidence and filesystem state. - Treat secrets found in history as exposed credentials and rotate/revoke them rather than merely editing history.
Verification chaininteractive parsed command → history admission/filtering → in-memory list → optional timestamps → session flush/append/write → HISTFILE → later recall/forensic correlation Boundary chain: local authoritative state → adjacent dependency → effective/programmed state → original workload/request → return/regression → explicit Evidence boundary. Boundary chain: local authoritative state → adjacent dependency → effective/programmed state → original workload/request → return path or regression → explicit Evidence boundary.
Failure boundaryBash history is convenience/lead evidence, not an authoritative audit trail; command presence/absence cannot independently prove execution or outcome. Boundary chain: process/context → userspace configuration → kernel subsystem/resource → device/network/filesystem dependency → effective state → original workload.
Persistence ruleProve which configuration source owns the state, then prove that the running consumer loaded or generated the intended state.
Confirmation

Confirm action

Continue?