In this lesson, you’ll learn how to list, search, and interactively navigate your Bash command history to boost your command-line productivity.Documentation Index
Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
Use this file to discover all available pages before exploring further.
1. List Your Bash History
Bash keeps track of every command entered in a session. To display your entire session history, use:2. Search Commands with grep
To filter history for specific keywords, pipe the output togrep. For example, to find all sudo invocations:
For comprehensive details on
grep, see the GNU grep Manual.3. Locate the .bash_history File
Bash writes your commands to~/.bash_history when you log out. To view hidden files in your home directory:
~/.bash_history in any text editor or display it with:
Commands executed in your current session only appear in
~/.bash_history after you log out.4. Navigate History Interactively
Bash lets you recall and edit past commands right in the prompt. Use these keystrokes:| Keystroke | Action |
|---|---|
| ↑ (Up Arrow) | Scroll backward to earlier commands |
| ↓ (Down Arrow) | Scroll forward to more recent commands |
| Ctrl + R | Reverse search through command history |