1

How can I prevent Bash from writing history entries to disk? My ~/.bashrccontains the line

trap 'unset HISTFILE; exit' SIGHUP

but it doesn't have the desired effect. If I run history -c && history -w; exit and open a new terminal, the history is empty, but if I type some more commands and exit, the commands are in the history when I open a new terminal. Any ideas?

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
August Karlstrom
  • 1,736
  • 2
  • 27
  • 39

1 Answers1

4

Put the following line in your ~/.bashrc:

unset HISTFILE

HISTFILE - The name of the file in which command history is saved. The default value is ~/.bash_history. If unset, the command history is not saved when a shell exits.

HISTFILE= works too.

Evgeny Vereshchagin
  • 5,286
  • 4
  • 35
  • 43
  • Yes, simply adding `unset HISTFILE` to `~/.bashrc` seems to work. If you clean up your answer I can accept it. – August Karlstrom Jul 07 '15 at 09:06
  • @AugustKarlstrom, ok. Bonus: [How do I open an incognito bash session?](http://unix.stackexchange.com/questions/158933/how-do-i-open-an-incognito-bash-session/211096#211096) – Evgeny Vereshchagin Jul 07 '15 at 09:55