Clear Bash History Completely in Linux

~/.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

The history comes back when you login back. The history entries has a copy in the memory and it will flush back to the file when you log out.

cat /dev/null > ~/.bash_history && history -c && exit

Alternative Method:

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.

Tags: ,