I tried adding history -c to ~/.bash_logout but seems not working.


I'm having success by adding these lines into my ~/.bashrc (referred from here)

export LESSHISTFILE=/dev/null

I still don't know why history -c method won't work.

  • history of what?! bash or all shells or the whole system please be more specific so edit your question to be so
    – Maythux
    Feb 18 '14 at 7:26
  • @maythux history of my bash shell commands that I typed. From SSH to be specific. History of whole system = history for all users?
    – checksum
    Feb 20 '14 at 7:20

There are many history settings available via the builtin command set -o or environment variables, see bash's documentation on its history facilities. From that, it follows that HISTFILE=/dev/null will let bash save the history into the void.

  • 2
    I also sometimes use kill -9 $$ which means less typing, but is not nice. $$ is the current process, i.e. the shell itself, and the forceful kill prevents it from writing to $HISTFILE, too. However, it also prevents it from doing other cleanups, and setting HISTFILE=/dev/null can be done much earlier (before leaving the shell), so one cannot accidentally quit the shell the wrong way. Plus, any intermediate history saving would also go to /dev/null.
    – hans_meine
    Feb 18 '14 at 8:39
  • Args, long docs. But anyhow I'm having success with your solution!
    – checksum
    Feb 20 '14 at 7:38
  • The environment variables are cleared after logout? Must it be done everytime?
    – JorgeeFG
    May 12 '15 at 13:33
  • Yes, all environment variables are cleared after logout. Basically, the whole environment's lifetime ends with the logout.
    – hans_meine
    May 13 '15 at 14:37

This will only work, if you are in a login shell and leave it by

  • exit or
  • logout or
  • press CtrlD.

If you simply close a Gnome Terminal, ~/bash_logout is not executed.

  • I use SSH with Putty. I did use both exit and close the ssh client straight away, but without success.
    – checksum
    Feb 20 '14 at 7:23

history -c will be available by default, you Don't have to add it , if need to remove every history try this , echo " " > ~/.bash_history

  • Without history -c, my history just accumulates with thousands of history lines.
    – checksum
    Feb 20 '14 at 7:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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