How to Clear Bash History on Linux

On this page

  1. Clear Bash History

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:

Suggested articles

1 Comment(s)

Add comment


From: Pete at: 2018-04-30 16:59:30

Don't forget that placing a space prior to any command will avoid adding it into the history at all.

It might be a good idea to require at least 5 characters in a command to be added as well.  Nobody needs 50 'ls' or 'mv' commands saved, right?  man bash has all the details.