Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to clear Bash terminal history in OS X El Capitan

After upgrading to OS X El Capitan (at least I noticed after update), in bash, history -c command does not work as usual.

History clearing only works for current tab. After opening another tab, it is possible to access history.

I know it is possibly to remove .bash_history file but actually I am curious about this new behaviour?

Maybe it is related to new .bash_sessions feature. Is there any way to use history -c as usual (clearing history across every bash instances)?

Thanks.

like image 829
Psychomentality Avatar asked Nov 30 '22 17:11

Psychomentality


2 Answers

HISTFILE Isn't ~/.bash_history

On OS X, the shell variable HISTFILE doesn't seem to point to ~/.bash_history. Instead, it points to some sort of temp file like:

/Users/$LOGNAME/.bash_sessions/7F058D96-4161-4F7C-B9F7-CFFEB43C35B2.historynew

As a result, history -c; history -w clears the current history buffer, but doesn't actually clear the on-disk history file. It's unclear to me how/when the HISTFILE is written to ~/.bash_history, so you may need to clear the file manually. For example:

history -c; history -w; rm ~/.bash_history
like image 90
Todd A. Jacobs Avatar answered Dec 14 '22 22:12

Todd A. Jacobs


I used:

cat /dev/null > ~/.bash_history && history -c

I used this topic, maybe you could find more info there?

like image 29
AAM111 Avatar answered Dec 14 '22 22:12

AAM111