[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Seeing command history when using MATE terminal



On Sat 18 Apr 2020 at 09:31:10 (-0400), songbird wrote:
> David wrote:
> > On Sat, 18 Apr 2020 at 20:20, Richard Owlett <rowlett@cloud85.net> wrote:
> >>
> >> I can see any *ONE* previous commands by using the up-arrow key.
> >> But I need to see the *complete* history. F1 is no "Help".
> >> Obviously its stored in a file. Where?
> >
> > Reading https://mywiki.wooledge.org/BashFAQ/088 gives some tips
> > that might be relevant if some history is missing:
> > * bash updates its history only on exit (unless history -a is used)
> > * and it overwrites the existing history file with the new version
> > * so if a user runs multiple shells, each shell exit will overwrite the existing
> > history file, the result is that only the last shell to exit will have
> > its history
> > preserved, and the history of the others will be lost.
> 
>   yes, that among other fun things made me decide to just
> remove the history file upon exit and then when it starts up
> each sesssion i preload the history stack with a few commands
> i use the most (using history -s "command") in .bashrc .

The behaviour of my bash is to read the current version of
.bash_history at startup into its internals (tomás's "belly"),
then to add new commands to its belly during the session.
Upon exiting, only these new commands are appended to the
version of the .bash_history file as it now exists (which
can be different at this later time).¹

I find that too confusing, with multiple bash sessions open
in X, and odd ones coming in over ssh, so my approach (of
about twenty years) is also to have a fixed history at startup,
(currently just under 200 lines) which is set readonly, and
then to throw any new typing away.

-r--r--r-- 13202 Apr  9 14:15 .bash_history
-rw-r--r-- 13202 Apr  9 14:15 .bash-edit-history

I maintain it by editing the second file here, and then
executing the following (which, obviously, is itself in
the history file):

chmod u+w ~/.bash_history; cp -ip ~/.bash-edit-history ~/.bash_history; chmod a-w ~/.bash_history

Many of the commands are designed for editing before they're
actually used, but the history file remembers the basic syntax.
Not surprisingly, find is one of the prime candidates:

find . -type f -mmin -1440 -printf '%Ta%TH:%TM:%.5TS%11s  %P\n' | sort -n -k 2 | less # one day
find . -type f -size "$( stat -c '%sc' xxx )" -printf '%s %TY-%Tm-%Td+%TH:%TM:%.5TS\t%P\n' | sort -k 3 # same size
find ~/newscores \( -name \*.ly -o -name \*.ily -o -name \*.lily \) -exec grep -Z -l -i 'x' {} \; | sort -z | xargs -0 less # display files

¹ Full disclosure: my own observations presuppose:

braceexpand:emacs:hashall:histexpand:history:interactive-comments:monitor:noclobber
is the value of SHELLOPTS, and I set these in .bashrc:
    set -o noclobber
    export HISTCONTROL=ignoreboth
Also, I don't type any actual history commands.

Cheers,
David.


Reply to: