Clear Bash History
Linux Bash History File
Check out more about bash history file.
Scrolling through Bash History
- UP arrow key: Scroll backwards in history
- CTRL-p: Scroll backwards in history
- DOWN arrow key: Scroll forwards in history
- CTRL-n: Scroll forwards in history
- ALT-Shift-.: Jump to the end of the history (most recent)
- ALT-Shift-,: Jump to the beginning of the history (most distant)
Linux Bash Search History
Checkout different ways to search Bash search history.
- History and Pipe to grep
history | egrep <cmd>
- CTRL-r to do bash reverse history search
press ctrl-r and type the partial or complete word of the command you are trying to search.
Example: In the above snapshot, I did following...
- ls ~/.bash_history
- Hit Enter
In step 3 above, after I press Ctrl+r, I typed "ba" and the whole command "ls ~/.bash_history" showed up.
Execute Previous Command Using ! (bang)
Use double bang as shown below...
If you want to execute previous command from history based on command number do following...
- history | less
- Note down the command number that you want to run
Example, let say you want to run command number 80, run following command...
If you want to run a command which was n number of commands before the current command, do following...
Example: Run 4th previous command.