Clear bash history

Written by NickWal

Delete bash history

Bash is a powerful, free, command line shell available in most Linux/Unix distributions. It has build in job control capabilities, in addition useful scripting capabilities. By default it maintains a history of up to the last 500 commands you have typed, which is clearly useful. However in an environment of shared computers and the need for increased privacy and security, its sometimes useful to be able to remove the history. This can be done easily.

  1. Make sure you have only one bash instance open with your username

  2. Use history -c && rm -f ~/.bash_history

  3. Your done!

Why does this work? Bash stores its history both in memory and in a file in the root of your home directory called .bash_history. In order to erase the history in bash, you must delete the history recorded in both places. You need to have the bash shell open only in one place, because if you clear it in one window, but not another, the .bash_history file will be re-written again by the ‘other’ bash shell (the one you didn’t erase) when it exits.

References