Your bash history is stored in a file called .bash_history which is located in your home directory. This file saves every command you run in bash and if you delete the file, it will automatically re-create itself when it has new data to save. I’m going to show you 2 ways to prevent this from happening. These methods can be used on any type of history or config file that behaves in this manner.
First, delete the bash history file.
As of this moment, your bash history has been erased. Now apply one of the following methods.
Method 1
Create a directory with the same name. The file will not be able to re-create itself because the name will be taken by the directory. This is the simplest method and it will work on any file system.
If you want to undo this, just delete the directory and the history file will re-create itself when it has data to save.
Method 2
This method will only work on an extended file system, which is most likely what you are using. Create a new empty file with the same name.
Change attributes on the file to make it immutable. When you make a file immutable, it can’t be modified, deleted, re-named, or linked to. Even by root.
If you want to undo this, you can run the following command to make the file mutable again.