2

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


Add:

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

unset HISTFILE
export LESSHISTFILE=/dev/null

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

2
  • 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, 2014 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, 2014 at 7:20

3 Answers 3

9

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.

4
  • 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, 2014 at 8:39
  • Args, long docs. But anyhow I'm having success with your solution!
    – checksum
    Feb 20, 2014 at 7:38
  • The environment variables are cleared after logout? Must it be done everytime?
    – JorgeeFG
    May 12, 2015 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, 2015 at 14:37
1

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.

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

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

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

You must log in to answer this question.

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