Use it to find what was run, repeat commands, or when history is missing or contains secrets.
Bash History
Bash history records the commands you type, stored in ~/.bash_history when the shell exits. history lists them; !n, !! and Ctrl+R recall them.
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.
command typed → kept in memory → appended/written to ~/.bash_history on exit (or history -a) → available to new shells
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
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
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 · 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.
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>).
history | tail— recent commandsbash -x script.sh— trace each expanded commandbash -n script.sh— syntax check onlyshellcheck script.sh— common bugs and quoting problemsecho $?— 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:
HISTFILEdefaults to~/.bash_history. If it's unset or empty, history isn't saved.HISTSIZE(default 500) limits the entries kept in memory, andHISTFILESIZElimits the lines kept in the file.HISTCONTROLacceptsignorespace,ignoredups,ignorebothanderasedups.HISTIGNOREis a colon-separated list of patterns that aren't saved.HISTTIMEFORMATadds timestamps.
A practical configuration
| Setting | Effect |
|---|---|
HISTSIZE=50000, HISTFILESIZE=100000 | Much longer history |
HISTCONTROL=ignoreboth | Skip duplicates and lines starting with a space |
HISTTIMEFORMAT='%F %T ' | Show when each command ran |
shopt -s histappend | Append instead of overwrite when several shells exit |
PROMPT_COMMAND='history -a' | Write each command immediately |
Reusing commands
| Shortcut | Meaning |
|---|---|
Ctrl-R | Reverse incremental search |
!! | The previous command (sudo !!) |
!$ | The last argument of the previous command |
!n / !-n | Command number n / n commands back |
^old^new | Repeat the previous command with a substitution |
history | grep ssh | Search the list |
fc | Edit 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.
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.
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
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
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%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.
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.
Quick lookup tables
Bash History operational reference
Topic-specific lookup boundaries, proof limits and next-step Evidence for Bash History.
| Lookup boundary | Topic-specific reference | Operational use |
|---|---|---|
| Scope / effective state | 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. | Establish exactly what this Topic owns before crossing into another subsystem. |
| Fast verification | Pin 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 chain | interactive parsed command → history admission/filtering → in-memory list → optional timestamps → session flush/append/write → HISTFILE → later recall/forensic correlation | Trace requested/configured state through effective state to the observed workload result. |
| Failure boundary | Bash 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 evidence | Correlated 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 correlation | Use this observation only for the specific claim it actually supports. |
| Evidence limit | It 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 check | Continue 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 boundary | Bash History |
|---|---|
| Topic path | Shell & Bash → Bash History |
| Runtime state | 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. |
| 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 chain | interactive 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 boundary | Bash 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 rule | Prove which configuration source owns the state, then prove that the running consumer loaded or generated the intended state. |