How to Clear Bash History in Linux, CentOS, Debian and Ubuntu



Sometimes you might want to hide the history of commands you typed in the shell on Linux.
This is useful when you are building a server image to roll out multiple virtual machines. The command shown below will work on all Linux Distributions (Linux, CentOS, Debian, Ubuntu, etc).

Clear Bash History

To clear the Bash History, use this combination of 3 commands
$ cat /dev/null > ~/.bash_history && history -c && exit

What do these commands do?


  • The cat command empties the .bash_history file of the currently logged in user.
  • The history -c command cleans the history of the current user session.
  • The exit command quits the current session.


Comments