6

I have freshly installed a new copy of El Capitan. I accidently deleted .bash_history, so I just did a touch .bash_history again, hoping this would solve the problem of my bash history not being remembered when closing and re-opening the terminal.

But it didn't. And I have no idea why.

Macbuech:~ josh$ ~/.bash_history
-bash: /Users/josh/.bash_history: Permission denied
Macbuech:~ josh$ ls ~/.bash_history
/Users/josh/.bash_history
Macbuech:~ josh$ echo $HISTSIZE
500
Macbuech:~ josh$ echo $HISTFILESIZE
500
Macbuech:~ josh$ echo $HISTFILE
/Users/josh/.bash_sessions/9817540A-F021-4E1A-93A1-B322BC4738AB.historynew
Macbuech:~ josh$ echo $HISTTIMEFORMAT

I fiddled around a bit with .bash_profile to get some colors working, according to this article:

export PS1="\[\033[36m\]\u\[\033[m\]@\[\033[32m\]\h:\[\033[33;1m\]\w\[\033[m\]\$ "
export CLICOLOR=1
export LSCOLORS=ExFxBxDxCxegedabagacad
alias ls='ls -GFh'

I removed all the stuff again to make sure the problem's not lying there. So here's my .bash_profile:

[[ -s "$HOME/.profile" ]] && source "$HOME/.profile" # Load the default .profile
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*

This site states that there may be a problem with RVM, and I tried adding a .bash_logout with shell_session_update in it, but no success.

Any help is highly appreciated.

Here's my complete env:

Macbuech:~ josh$ env
rvm_bin_path=/Users/josh/.rvm/bin
TERM_PROGRAM=Apple_Terminal
GEM_HOME=/Users/josh/.rvm/gems/ruby-2.2.4
SHELL=/bin/bash
TERM=xterm-256color
IRBRC=/Users/josh/.rvm/rubies/ruby-2.2.4/.irbrc
TMPDIR=/var/folders/sq/92dr708946s01kttg916m6xm0000gn/T/
Apple_PubSub_Socket_Render=/private/tmp/com.apple.launchd.9AJd6SsR1y/Render
TERM_PROGRAM_VERSION=361.1
MY_RUBY_HOME=/Users/josh/.rvm/rubies/ruby-2.2.4
TERM_SESSION_ID=9817540A-F021-4E1A-93A1-B322BC4738AB
rvm_stored_umask=0022
USER=josh
_system_type=Darwin
rvm_path=/Users/josh/.rvm
SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.gZZeyimp2O/Listeners
__CF_USER_TEXT_ENCODING=0x1F5:0x0:0x0
rvm_prefix=/Users/josh
PATH=/Users/josh/.rvm/gems/ruby-2.2.4/bin:/Users/josh/.rvm/gems/ruby-2.2.4@global/bin:/Users/josh/.rvm/rubies/ruby-2.2.4/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/josh/.rvm/bin
rvm_loaded_flag=1
PWD=/Users/josh
_system_arch=x86_64
XPC_FLAGS=0x0
_system_version=10.11
XPC_SERVICE_NAME=0
rvm_version=1.26.11 (master)
SHLVL=1
HOME=/Users/josh
LOGNAME=josh
GEM_PATH=/Users/josh/.rvm/gems/ruby-2.2.4:/Users/josh/.rvm/gems/ruby-2.2.4@global
LC_CTYPE=UTF-8
RUBY_VERSION=ruby-2.2.4
rvm_user_install_flag=1
_system_name=OSX
_=/usr/bin/env
5
  • What's the output for ls -la ~/.bash_history ? Maybe it's permissions problem? Here's my: -rw------- 1 myusername staff 10852 18 gru 20:41 /Users/myusername/.bash_history Dec 31, 2015 at 15:36
  • $ ls -la ~/.bash_history -rw-r--r-- 1 josh staff 3B Dec 31 08:38 /Users/josh/.bash_history Dec 31, 2015 at 15:49
  • Did you restart the shell (or Terminal itself) after touching .bash_history?
    – nohillside
    Jan 11, 2016 at 16:29
  • For sure I did. Jan 12, 2016 at 15:04
  • Could you temporarily remove your ~/.bash_profile, start a new login shell, check if you have the same problem, report this in your OQ.
    – dan
    Jan 16, 2016 at 15:23

2 Answers 2

10
+50

I encountered the same problem after willingly deleting the .bash_history file.

The simple solution is to not only touch the file but also add some text - one or several line feeds are not sufficient:

echo "exit" >> ~/.bash_history

Then completely quit Terminal and reopen it. If you've saved all your work in all terminal sessions, you can also just

killall Terminal

Update:

I tried to replicate your environment in a 10.11 VM and it's indeed a problem with RVM: commenting out all rvm related lines in .profile and .bash_profile re-enables updates of the .bash_history file.

The .bash_logout file method (with the content shell_session_update) seems to work reliably here though. Just remember to always enter exit before closing a Terminal window or quitting Terminal. Without entering exit the history won't be updated.

11
  • 1
    And now the obvious question: why? Does the file need a new-line character or just any character? Jan 11, 2016 at 15:49
  • Doesn't seem to work for me. I have a few lines in my history, but no new entries are added. Jan 12, 2016 at 15:04
  • ls and exit, with no new line at the end: ls\nexit Jan 13, 2016 at 14:12
  • Still doesn't work. Jan 13, 2016 at 15:01
  • How can this be done, disabling the .bash_profile? Jan 13, 2016 at 15:42
0

You need to recreate the file with "nano", no with "touch". Run this command on terminal, in your home folder (/Users/Your-Username):

nano .bash_history

Type anything in the file (otherwise it won't be created), exit and save.

Hope this help.

4
  • How does this differ from the answer already given?
    – nohillside
    Jan 16, 2016 at 11:06
  • Get the expected result in a more simplified form, it is the only difference @patrix . Regards. Jan 16, 2016 at 14:40
  • Doesn't change a thing, either. Is it maybe because I have different terminal windows open, with each having a few tabs? Jan 16, 2016 at 17:35
  • @JoshuaMuheim That probably causes it, but could not be sure, I have not studied in detail the operation of ".bash_history" behavior in osx "El Captain". What if I can say for sure is that each terminal session in osx, saves changes to the ".bash_history" file until you close the window or run the output command "exit", the file is not locked while the session is active. Jan 16, 2016 at 20:41

You must log in to answer this question.

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