Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

10.7x Lion Terminal Command History, not working

For the love of God, might someone here have a definitive answer on this.


For some reason I have lost the ability in the Terminal to bring up command history, by using the Up arrow.


It will work within a current Terminal session, but once you Quit Terminal app, and reopen it, forget it. No command history.


You just get OS X's system alert sound.


I have scoured the web all of over on this: .bash_profile , and .bashrc files. Tons of articles. Do not work.


This could be related to a popular script that is out there for Lion, that basically turns Window and App Restore totally Off, even if you forget to close apps on logout, or perhaps not.


thanks in advance.


johnfromlosangeles

MacBook Pro, Mac OS X (10.7.3)

Posted on May 2, 2012 6:33 PM

Reply
12 replies

May 2, 2012 7:13 PM in response to johnfromlos angeles

johnfromlos angeles wrote:


I have scoured the web all of over on this: .bash_profile , and .bashrc files. Tons of articles. Do not work.


Is there a .bash_login or .profile?


You should probably be looking for the settings of the following two predefined bash shell variables (or define them yourself in your .bashrc):


HISTFILESIZE = the max (line) size of the HISTFILE (the file containing the history)


HISTSIZE = the max number of lines retained in the HISTFILE when an interactive bash shell is launched


You probably want both HISTFILESIZE and HISTSIZE defined as the same number.


This could be related to a popular script that is out there for Lion, that basically turns Window and App Restore totally Off, even if you forget to close apps on logout, or perhaps not.


Do you have a link (url) to the source of that script?

May 3, 2012 6:15 AM in response to johnfromlos angeles

If the .bash_history has permissions that DO NOT allow you write access, the shell will NOT be able to store your current session history for the next time.


This can also happen if .bash_history is not a regular file (if the file does not exist, bash will create it)


If the home directory is NOT writable by the user, then bash wiill not be able to create .bash_history


If HISTFILE points to a locations that does not exist, or if the location it points to is not writable by the user, then bash will not be able to save the file. And if HISTFILE should point to /dev/null, it will save the session history in a bottomless pit :-)


In my experience, not being able to write the .bash_history has been the reason for not seeing your history the next session.


The other bit of fun is if you have multiple terminal windows or tabs and all of them want to write to the same .bash_history which generally means the last session to close wins the battle of what commands are saved :-)

May 3, 2012 11:46 AM in response to BobHarris

Thanks guys appreciate it.


This has been bugging me for months. Finally decided I would figure out why this is happening.


The Lion "no window / app restore" shell script was not the issue. As I tested it and the script does not break the terminal history for a new user.


Bob, I believe you nailed it. It think it had to do with permissions. In any event, a new user profile, fixed the issue.


Terminal history is back once again. Awesome. I cruise around in temrinal a lot and having the history is so convenient.


If I may inquire. chmod seems crazy, even after reading man chmod. I still use BatchMod just to make it easier.


Is there some cheat sheet or easy way to remember read / write / execute commands in chmod.


I know to make a file executable: chmod u+x filename, but what about just read/write access? files?, folders?


Bob, out of curiousty, where in New England? Boston?. Born and raised in Connecticut.


Thanks,


jfla

May 3, 2012 12:33 PM in response to johnfromlos angeles

If I may inquire. chmod seems crazy, even after reading man chmod. I still use BatchMod just to make it easier.


Is there some cheat sheet or easy way to remember read / write / execute commands in chmod.


I know to make a file executable: chmod u+x filename, but what about just read/write access? files?, folders?


First, I've been playing with these commands since '85, before GUI's. I can even apply permissions using the octal values without thinking too hard. 🙂 Of couse it doesn't hurt that I also work on file systems in my day job.


chmod +r filename

chmod +w filename

chmod +rw filename

chmod +rwx filename


You can use a+ for all or ugo+ to do the same thing


chmod a+rwx filename

chmod ugo+rwx filename


And you can use - to take away permissions


chmod a-w filename


Of course be careful about doing wildcard changes to give yourself access, as some apps get really upset if the permissions are too permissible.


Bob, out of curiousty, where in New England? Boston?. Born and raised in Connecticut.


Raised in Penna (80 miles north of Philly)


Currently reside north of Boston in the burbs and work in Nashua, NH. I had been working for mini-computer company founded in Mass, that merged with a Texas PC company, that was acquired by a printer company. Then the printer company cancelled our project and toss 300 of us out. I work for someone else now (but I still get a discount on the printers and printer supplies 🙂 ).

May 3, 2012 12:37 PM in response to johnfromlos angeles

johnfromlos angeles wrote:


Is there some cheat sheet or easy way to remember read / write / execute commands in chmod.


I know to make a file executable: chmod u+x filename, but what about just read/write access? files?, folders?


Think of the r/w/x flags as bits (which they are). So you have users/group/others as three sets of three bits, i.e., r/w/x r/w/x r/w/x respectively. So if you wanted to give only users and groups read and execute access you would have in binary 101 101 000, or 550 octal. Then a chmod 550 would do just that since the chmod accepts the mode in octal as an alternative to the symbolic forms. I find this easier than using the symbolic forms.

May 3, 2012 1:22 PM in response to X423424X

Think of the r/w/x flags as bits (which they are). So you have users/group/others as three sets of three bits, i.e., r/w/x r/w/x r/w/x respectively. So if you wanted to give only users and groups read and execute access you would have in binary 101 101 000, or 550 octal. Then a chmod 550 would do just that since the chmod accepts the mode in octal as an alternative to the symbolic forms. I find this easier than using the symbolic forms.


Yea, but you most likely started playing with this stuff when punch paper tape and 80 column cards were the stnadard for entering data into a computer 😉


My first job was writing hardware diagonstics for a card punch 🙂


Message was edited by: BobHarris

May 3, 2012 3:05 PM in response to BobHarris

BobHarris wrote:


Yea, but you most likely started playing with this stuff when punch paper tape and 80 column cards were the stnadard for entering data into a computer 😉


My first job was writing hardware diagonstics for a card punch 🙂


Heh 😀 Yup, I guess that dates me. I spent many hours on keypunches and ttys with paper tape coding for Algol and Fortran compilers. That should really date me!

Jul 23, 2012 1:07 PM in response to johnfromlos angeles


@johnfromlos angeles: Even though you are already satisfied by creating a new profile (that got Terminal behaving normally), and even also that Bob (and others) explained the most logical reasons why the history were not stored, I would humbly offer a simpler answer (because that's what happened in my case):

As others said, if Terminal is using bash, the history is stored in your home directory in ~/.bash_history.

Check first in your home directory the permissions and who owns the file .bash_history


ls -al .bash_history


If for some reason the file is not owned by your username, it will appear in the listing as (in this example the owner is root):


-rw------- 1 root staff 32 Jul 11 2011 .bash_history


Fix it with (replace [username] with your actual username):


sudo chown [username] .bash_history


Now close Terminal, open it again and you should be capable of seeing previously entered commands by pressing the up arrow. (source: http://www.paulmc.org/2009/01/enable-bash-history-in-terminal/)

10.7x Lion Terminal Command History, not working

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.