How to clear bash history completely?
Solution 1:
The file ~/.bash_history
holds the history.
To clear the bash history completely on the server, open terminal and type
cat /dev/null > ~/.bash_history
Other alternate way is to link ~/.bash_history
to /dev/null
However,
One annoying side-effect is that the history entries has a copy in the memory and it will flush back to the file when you log out.
To workaround this, use the following command (worked for me):
cat /dev/null > ~/.bash_history && history -c && exit
Solution 2:
What to do:
In every open bash shell (you may have multiple terminals open):
history -c
history -w
Why:
As noted above, history -c
empties the file ~/.bash_history
. It is important to note that bash shell does not immediately flush history to the bash_history file. So, it is important to (1) flush the history to the file, and (2) clear the history, in all terminals. That's what the commands above do.
Reference: http://www.giannistsakiris.com/index.php/2007/09/13/how-to-clear-bash-history-and-what-to-watch-out-for/
Solution 3:
execute the following commands to clear history forever
history -c && history -w
good luck!