How to Clear Bash History on Linux

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

Clear Bash History

To clear the Bash History on Linux, 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.

Share this page:

how to clear bash history on
how to clear bash history on linux 1
how to clear bash history on linux 2
how to clear bash history on linux 3

نوشته های مشابه