How to Clear Bash History on Linux

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).if(typeof __ez_fad_position != ‘undefined’){__ez_fad_position(‘div-gpt-ad-howtoforge_com-box-3-0’)};

Clear Bash History

To clear the Bash History on Linux, use this combination of 3 commands:if(typeof __ez_fad_position != ‘undefined’){__ez_fad_position(‘div-gpt-ad-howtoforge_com-medrectangle-3-0’)};

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.
About the Author

Leave a Reply