Bash history
This page was last updated on July 18, 2009.
- Auto-complete a command that you’ve made before:
- Press the Ctrl and r keys at the same time.
- Start typing the command. It will suggest the most recent match.
- Continue typing the command until you have the match you want.
- Press the Enter key.
- Check Bash history of a command:
- Type this command in a terminal window, replacing foo with the name of the command you’d like to check:
grep -a foo .bash_history
- Clear Bash history:
- Type this command in a terminal window:
history -c
- Display the last 500 commands you typed:
- Type this command in a terminal window:
history
- Select one of the last 500 commands you typed by number:
- Type this command in a terminal window, replacing n with the number of the command from the Bash history:
!n
Each command you enter changes the numbering of the last 500 commands, so check the list before choosing a number.
- Re-enter the last command
- Type this command in a terminal window:
!!
- Run the *most recent* command that starts with specific letters
- Type this command in a terminal window, replacing foo with the first few letters of the command you’re looking for:
!foo
- Search Bash history
- Use your up and down arrow keys to scroll through the Bash history.
- Or type this command im a terminal window, replacing foo with the command you’re looking for:
history | grep foo
Obligatory Happy Ending
And they all lived happily ever after. The end.

Comment: