You are not logged in.

#1 2011-03-10 23:27:13

Daerun
Member
Registered: 2011-02-07
Posts: 92

[SOLVED] Terminal doesn't remember last commands

I noticed this problem yesterday: terminal only remembers commands I entered three days ago, starting today, last of them being the pacman -Syu I performed on tuesday. From that point onward, it "forgets" all commands every time I close it neutral

Last edited by Daerun (2011-03-11 23:22:04)

Offline

#2 2011-03-10 23:38:54

xxxspuddy
Member
Registered: 2007-05-15
Posts: 57

Re: [SOLVED] Terminal doesn't remember last commands

Which shell are you using? If bash, do you have write permission to ~/.bash_history?


A temporary file is just a pipe with an attitude and a will to live.

Offline

#3 2011-03-10 23:40:47

Allan
Pacman
From: Brisbane, AU
Registered: 2007-06-09
Posts: 11,365
Website

Re: [SOLVED] Terminal doesn't remember last commands

Known upstream issue.   Exit your terminal using "exit" or "ctrl+d" rather than closing the window.

Offline

#4 2011-03-11 09:01:58

Daerun
Member
Registered: 2011-02-07
Posts: 92

Re: [SOLVED] Terminal doesn't remember last commands

Allan wrote:

Known upstream issue.   Exit your terminal using "exit" or "ctrl+d" rather than closing the window.

Really? lol But How is it that older commands are there? I've always closed it via mouse...

Offline

#5 2011-03-11 09:17:22

Allan
Pacman
From: Brisbane, AU
Registered: 2007-06-09
Posts: 11,365
Website

Re: [SOLVED] Terminal doesn't remember last commands

It started with bash-4.2

Offline

#6 2011-03-11 11:35:28

blasse
Member
From: Poland
Registered: 2008-04-24
Posts: 303

Re: [SOLVED] Terminal doesn't remember last commands

Add to your .bashrc

export PROMPT_COMMAND="history -a; history -n; $PROMPT_COMMAND" 

It will mix history between open terminal windows, but it will also remember history wink


Proud ex-maintainer of firefox-pgo

Offline

#7 2011-03-11 17:08:53

darkbeanies
Member
Registered: 2009-01-14
Posts: 142

Re: [SOLVED] Terminal doesn't remember last commands

blasse wrote:

Add to your .bashrc

export PROMPT_COMMAND="history -a; history -n; $PROMPT_COMMAND" 

It will mix history between open terminal windows, but it will also remember history wink

Hooray!  As a habitual button clicker, it was driving me mad trying to remember to exit every time.  Thanks for this useful tip!

Offline

#8 2011-03-11 23:20:53

Daerun
Member
Registered: 2011-02-07
Posts: 92

Re: [SOLVED] Terminal doesn't remember last commands

Yup, that works, thanks smile

Last edited by Daerun (2011-03-11 23:21:08)

Offline

#9 2011-03-15 01:40:37

beber75
Member
Registered: 2009-07-16
Posts: 24
Website

Re: [SOLVED] Terminal doesn't remember last commands

@blasse your amazing, thanks for the tip.

Offline

#10 2011-03-15 09:36:46

mhertz
Member
From: Denmark
Registered: 2010-06-19
Posts: 681

Re: [SOLVED] Terminal doesn't remember last commands

The 'history' command accepts concatenated parameters, so instead of 'history -a; history -n', you can just use 'history -an'. Also, the preceding 'export' is redundant in this occasion.

Btw, I myself always use 'history -a' as 'PROMPT_COMMAND', which makes new terminals opened inherit the history of the current terminals running, but I do not like the 'history -n' option, which will make all open terminals continously inherit each others history.

It's a matter of personal preference obviously, but check out the following example:

When for example you open a terminal just to start some server. Then you open another terminal and play around for a while. Then you want to restart the server process, so you go back to that terminal and Ctrl+C it and hit UP to go back in your history to re-run the server command. But oops, now a lot of commands are in between you and the one you want...

The 'history -a' command will overcome the above problem, but if you don't care about isolating each terminals own history from the others, then 'history -an' makes better sence... (imho, of course...)

Both ways will obviously also fix this bash issue, as it's the 'history -a' option which fixes it i.e. writes the history to file upon each return/enter press...

Offline

#11 2011-03-15 19:14:16

zippy
Member
Registered: 2009-02-01
Posts: 54

Re: [SOLVED] Terminal doesn't remember last commands

$ history -an
bash: history: cannot use more than one of -anrw

Offline

#12 2011-03-16 11:40:51

mhertz
Member
From: Denmark
Registered: 2010-06-19
Posts: 681

Re: [SOLVED] Terminal doesn't remember last commands

@zippy + all

I apologise for posting wrong information, and thanks for the correction!

I had read on another forum someone stating that you could just use 'history -an' instead of 'history -a; history -n', and I just remembered that, when I saw this thread. I always myself just prefer to use 'history -a', so I haden't tested the 'history -an' command personally and just took the tip of that other forum to be true...

Again, sorry about that!

Edit: I got it from here: http://briancarper.net/blog/248/

Quoth Amos on June 11, 2010 @ 4:04 PM PDT
Thanks for the tip.

A couple of small corrections

1.It's not necessary to "export" PROMPT_COMMAND (i.e. it doesn't need to be set as an environment variable). It's enough to do "PROMPT_COMMAND='history -n'".

2.If you want to keep running both then you can just set PROMPT_COMMAND to "history -an". Although after reading the comments here I agree that the -n is going to be annoying.

Last edited by mhertz (2011-03-16 12:03:06)

Offline

Board footer

Powered by FluxBB