Pcornel
Linux · Shell & Bash

Bash History

Cheat sheet · https://pcornel.dk/topic.php?topic=2691

Back to the Topic

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.

Remember

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>).

First 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

Commands

sudo !!

Verify in this order

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

Where it usually breaks

First mismatch in persistent intent → provider/parser/generator → kernel/userspace runtime → dependency/security context → logs/counters → consumer-visible read-back; preserve identity/native diagnostic/pre-state before mutation.

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=2691

Confirmation

Confirm action

Continue?