Using KDE Konsole as a bash terminal I would like to clear the history when I close the terminal (tab/application), note that I do need the bash history when Konsole is still open (to search it); I would like to have it cleared once the terminal is closed.
I often use the terminal for a long time and clear the history before I close the terminal, I am looking for a way to automate the clearing of the history.
I found a similar questions on how to clear the history or how to disable it like How do I close a terminal without saving the history?, however I found nothing helpful for my situation. The difference here is that i do need the history file while the terminal is running, setting unset HISTFILE
disable the history file after that command is ran and does not clear the history file itself. Note that the history file is needed while the session is running but when it get closed it need to be cleared.
How can we clear the bash history when the terminal gets closed?
~/.bashrc
. Do you have a history add in (for example) your shell prompt? – ctrl-alt-delor May 27 '20 at 22:08trap "history -c" EXIT
– Yunus May 27 '20 at 22:26unset HISTFILE
disable the history file after that command is ran and does not clear the history file itself. The history file is needed while the session is running but when it get closed it need to be cleared. some answers here solve the question :) – origami May 30 '20 at 14:52HISTFILE
does (it tells bash not save history contents after exiting - it does not affect the history mechanism whilst using bash). What may be confusing you that.bash_history
may already have entries in it. In which caserm ~/.bash_history
and then the unsetHISTFILE
setting will no longer re-create it. – Drav Sloan Jun 03 '20 at 12:27