All HowTo's Cybersecurity Linux

Deleting the Bash History

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:

  1. Open the first terminal and delete the history file contents like this “> ~/.bash_history”.
  2. Open the second terminal and confirm that your history is empty.
  3. 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.

Leave a Reply

Your email address will not be published. Required fields are marked *