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?

2
  • 1
    Have you tried removing write permission on the history file? Jul 7, 2015 at 6:17
  • @UlrichSchwarz That works but in my book it's more of a workaround than a clean solution. Jul 7, 2015 at 6:22

1 Answer 1

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.

2

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .