MacOS – OSX Terminal no longer save the commands in history

command linemacosterminal

Here's my issue. Last week I realized that my OSX (10.11.13) Terminal no longer saves the command I execute in the history file(s).

To be more clear:

  1. I type the command test
  2. On the same terminal window, I press arrow up: it's ok, test is there
  3. If I close the terminal, reopen it and press arrow up: test is no longer there (so it jumps to a command I executed weeks ago).

Here's what printenv returns :

NVM_RC_VERSION=
rvm_bin_path=/Users/my-user/.rvm/bin
TERM_PROGRAM=Apple_Terminal
GEM_HOME=/Users/my-user/.rvm/gems/ruby-2.1.2
SHELL=/bin/bash
TERM=xterm-256color
IRBRC=/Users/my-user/.rvm/rubies/ruby-2.1.2/.irbrc
TMPDIR=/var/folders/4x/y0j5261j7j3142sx_82m6fxm0000gn/T/
Apple_PubSub_Socket_Render=/private/tmp/com.apple.launchd.JLKMtkE4S1/Render
TERM_PROGRAM_VERSION=361.1
MY_RUBY_HOME=/Users/my-user/.rvm/rubies/ruby-2.1.2
TERM_SESSION_ID=B48F774F-86DA-4AA1-BAB7-888DCBA65E5A
NVM_DIR=/Users/my-user/.nvm
USER=my-user
_system_type=Darwin
rvm_path=/Users/my-user/.rvm
SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.550eXpVGiK/Listeners
__CF_USER_TEXT_ENCODING=0x1F5:0x0:0x1
rvm_prefix=/Users/my-user
PATH=/opt/local/bin:/opt/local/sbin:/Applications/MAMP/Library/bin:/Applications/MAMP/bin/php/php5.5.3/bin:/Users/my-user/.rvm/gems/ruby-2.1.2/bin:/Users/my-user/.rvm/gems/ruby-2.1.2@global/bin:/Users/my-user/.rvm/rubies/ruby-2.1.2/bin:/Applications/MAMP/bin/php/php5.3.6/bin:/usr/local/mysql/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Users/my-user/.rvm/bin:/sdk/android/platform-tools:/sdk/android/tools
NVM_NODEJS_ORG_MIRROR=https://nodejs.org/dist
PWD=/Users/my-user
LANG=fr_FR.UTF-8
_system_arch=x86_64
XPC_FLAGS=0x0
_system_version=10.11
XPC_SERVICE_NAME=0
rvm_version=1.25.15 (stable)
SHLVL=1
HOME=/Users/my-user
LOGNAME=my-user
GEM_PATH=/Users/my-user/.rvm/gems/ruby-2.1.2:/Users/my-user/.rvm/gems/ruby-2.1.2@global
NVM_IOJS_ORG_MIRROR=https://iojs.org/dist
_system_name=OSX
_=/usr/bin/printenv

Any help?

Best Answer

Based on this question and answer the following should work:

  • Disable ~/.profile and ~/.bash:profile by renaming it:

    mv ~/.bash_profile ~/off.bash_profile
    mv ~/.profile ~/off.profile
    
  • Create a new file ~/.bash_logout with the content shell_session_update

    echo "shell_session_update" > ~/.bash_logout
    
  • Enter killall Terminal
  • Open Terminal and enable ~/.profile and ~/.bash_profile by renaming it:

    mv ~/off.bash_profile ~/.bash_profile
    mv ~/off.profile ~/.profile
    
  • Enter killall Terminal

  • Open Terminal and check the behavior now. Remember to always enter exit now before closing a Terminal window or quitting Terminal.