Skip to main content
In this lesson, you’ll learn how to list, search, and interactively navigate your Bash command history to boost your command-line productivity.

1. List Your Bash History

Bash keeps track of every command entered in a session. To display your entire session history, use:
Example output:

2. Search Commands with grep

To filter history for specific keywords, pipe the output to grep. For example, to find all sudo invocations:
Output:
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:
Sample listing:
You can open ~/.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: When you find the desired entry, press Enter to re-execute or edit it inline.

Additional Resources

Watch Video