There are times when you want to clear out the Bash history and make a clean start. Or perhaps you want to remove a single or select item/s from the Bash history. Both of these scenarios are accomplished as described below – although we’ll focus on clearing out the entire Bash history.
Note that if the Bash history is sent to Syslog and then over to a centralised logging server, then simply deleting the Bash history (or a single line from the Bash history) from the system is less effective.
The Bash history is loaded into memory from the “~/.bash_history” file at the beginning of each Bash session. The Bash history is saved to that same file at the end of each Bash session.
The solution to successfully deleting your Bash history is to use multiple terminals. Here’s the process:
- Open the first terminal and delete the history file contents like this “> ~/.bash_history”.
- Open the second terminal and confirm that your history is empty.
- Close the first terminal and then close the second terminal.
The last Bash session to close has it’s history overwrite the previous saves to that file.
At this point, any future bash sessions will show an empty (or nearly empty) Bash history.