See, recall and reuse past commands quickly with the shell builtin history. 16.11.2025 | reading time: 2 min Every command you typed is not lost; the shell keeps a list you can inspect and reuse with the builtin `history` command, which helps when troubleshooting and automating repetitive tasks. Live Demo Try this short session on a shell to see `history` at work: ```bash # run a few commands ls -la cd /etc cat hosts history 5 ``` The `history 5` output might look like: ```text 101 ls -la 102 cd /etc 103 cat hosts 104 history 5 105 echo hello ``` You can re-run the `cat hosts` command with its event number: ```bash !103 ``` and use `!!` to repeat the last command or `!cat` to repeat the last command starting with "cat". Deeper Controls View only the last N entries with `history N`, remove an entry with `history -d <offset>`, clear the session list with `history -c`, and persist changes with `history -a` or reload with `history -r`; enable timestamps for readable dates by setting `HISTTIMEFORMAT` and avoid leaking secrets by configuring `HISTCONTROL`, `HISTIGNORE` or by unsetting `HISTFILE`. Related Tools The shell history pairs well with `grep` to find patterns like `history | grep ssh`, with `fc` to edit and re-run complex commands, and with interactive reverse search (Ctrl+R) for quick recall; remember that behavior differs a bit between bash and zsh so check the shell manual. Next Steps Start using `history` in real troubleshooting sessions, combine it with filtering and editing, and make your workflow repeatable; to deepen knowledge and prepare for certification consider training and exam preparation such as CompTIA Linux+ or LPIC-1 with intensive courses at bitsandbytes.academy. Join Bits & Bytes Academy First class LINUX exam preparation. utilities scripting troubleshooting