Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
1  
Have you tried removing write permission on the history file? – Ulrich Schwarz Jul 7 '15 at 6:17
    
@UlrichSchwarz That works but in my book it's more of a workaround than a clean solution. – August Karlstrom Jul 7 '15 at 6:22
up vote 4 down vote accepted

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.

share|improve this answer
    
Yes, simply adding unset HISTFILE to ~/.bashrc seems to work. If you clean up your answer I can accept it. – August Karlstrom Jul 7 '15 at 9:06
    
@AugustKarlstrom, ok. Bonus: How do I open an incognito bash session? – Evgeny Vereshchagin Jul 7 '15 at 9:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.