ubuntu/unix command line "history"
Paul Smith
paul at mad-scientist.net
Tue Oct 16 17:38:49 UTC 2012
On Tue, 2012-10-16 at 13:12 -0400, ping wrote:
>
> On 10/16/2012 12:09 PM, Tony Arnold wrote:
> > On 16/10/12 16:54, ping wrote:
> >
> >> what happens? each terminal maintains a seperate instance of command
> >> line history? is there a method that I can always rely on to find out my
> >> old command?
> >
> > By deafult when a shell exits, the history file gets over written
> > completely so you lose any history from previous shell invocations.
> >
> > You can use 'shopt histappend' in your .bashrc file to cause the history
> > file to be appended to when a shell exits instead of being over written.
> >
> > This is described in man bash under SHELL BUILTIN COMMANDS.
>
> I already had that options:
>
> 14 # append to the history file, don't overwrite it
>
> 15 shopt -s histappend
>
> 16
>
> but looks doesn't help.
>
> here for example, I have 2 different view of the history in 2 terminals:
You have a misunderstanding of how history works in bash. The bash man
page does explain it:
On startup, the history is initialized from the file named by the vari-
able HISTFILE (default ~/.bash_history). [...] When an inter-
active shell exits, the last $HISTSIZE lines are copied from the his-
tory list to $HISTFILE. If the histappend shell option is enabled (see
the description of shopt under SHELL BUILTIN COMMANDS below), the lines
are appended to the history file, otherwise the history file is over-
written.
So to be clear: when your shell starts it seeds its internal history
(which exists only in memory) with the contents of the history file.
While your shell is running, it keeps its history internally in memory.
When your shell exits, it writes (or appends) its internal history to
the file.
So, it's never the case that as you run commands in one shell, those
commands will dynamically appear in the history of another shell. The
history is only "shared" when a shell exits, and only new shells will be
able to see it.
HTH!
More information about the ubuntu-users
mailing list