Bash_history in Void

Does your home directory look like this?

[nevj@trinity ~]$  ls -a
.                        .bash_history-04364.tmp  .bash_history-05492.tmp
..                       .bash_history-04366.tmp  .bash_history-05789.tmp
.ICEauthority            .bash_history-04381.tmp  .bash_history-06131.tmp
.Xauthority              .bash_history-04386.tmp  .bash_history-06800.tmp
.bash_history            .bash_history-04387.tmp  .bash_history-06875.tmp
.bash_history-00770.tmp  .bash_history-04392.tmp  .bash_history-06880.tmp
.bash_history-01653.tmp  .bash_history-04398.tmp  .bash_history-06893.tmp
.bash_history-02750.tmp  .bash_history-04401.tmp  .bash_history-07447.tmp
.bash_history-02770.tmp  .bash_history-04416.tmp  .bash_history-08105.tmp
.bash_history-02806.tmp  .bash_history-04420.tmp  .bash_history-09866.tmp
.bash_history-02832.tmp  .bash_history-04422.tmp  .bash_history-09893.tmp
.bash_history-02842.tmp  .bash_history-04423.tmp  .bash_history-10031.tmp
.bash_history-02857.tmp  .bash_history-04426.tmp  .bash_history-10056.tmp
.bash_history-02881.tmp  .bash_history-04427.tmp  .bash_history-10058.tmp
.bash_history-02895.tmp  .bash_history-04430.tmp  .bash_history-11225.tmp
.bash_history-02907.tmp  .bash_history-04432.tmp  .bash_history-11277.tmp
.bash_history-02910.tmp  .bash_history-04439.tmp  .bash_history-11663.tmp
.bash_history-02916.tmp  .bash_history-04441.tmp  .bash_history-12302.tmp
.bash_history-02945.tmp  .bash_history-04447.tmp  .bash_history-12403.tmp
.bash_history-02988.tmp  .bash_history-04450.tmp  .bash_history-14934.tmp
.bash_history-02989.tmp  .bash_history-04458.tmp  .bash_history-15729.tmp
.bash_history-03003.tmp  .bash_history-04460.tmp  .bash_history-16711.tmp
.bash_history-03008.tmp  .bash_history-04465.tmp  .bash_history-21598.tmp
.bash_history-03014.tmp  .bash_history-04467.tmp  .bash_history-21925.tmp
.bash_history-03079.tmp  .bash_history-04469.tmp  .bash_history-26563.tmp
.bash_history-03143.tmp  .bash_history-04471.tmp  .bash_logout
.bash_history-03148.tmp  .bash_history-04478.tmp  .bash_profile
.bash_history-03196.tmp  .bash_history-04482.tmp  .bashrc
.bash_history-03223.tmp  .bash_history-04500.tmp  .cache
.bash_history-03266.tmp  .bash_history-04506.tmp  .cargo
.bash_history-03436.tmp  .bash_history-04507.tmp  .chatgpt.login
.bash_history-03444.tmp  .bash_history-04525.tmp  .config
.bash_history-03452.tmp  .bash_history-04527.tmp  .conkyrc.antix
.bash_history-03463.tmp  .bash_history-04529.tmp  .dbus
.bash_history-03492.tmp  .bash_history-04556.tmp  .gitconfig
.bash_history-03743.tmp  .bash_history-04561.tmp  .github.token
.bash_history-03819.tmp  .bash_history-04564.tmp  .gnupg
.bash_history-03848.tmp  .bash_history-04579.tmp  .inputrc
.bash_history-03884.tmp  .bash_history-04585.tmp  .java
.bash_history-03913.tmp  .bash_history-04589.tmp  .keenwrite.xml
.bash_history-03928.tmp  .bash_history-04590.tmp  .lesshst
.bash_history-03947.tmp  .bash_history-04610.tmp  .local
.bash_history-03986.tmp  .bash_history-04615.tmp  .mozilla
.bash_history-04054.tmp  .bash_history-04617.tmp  .pki
.bash_history-04059.tmp  .bash_history-04643.tmp  .profile
.bash_history-04062.tmp  .bash_history-04644.tmp  .putty
.bash_history-04069.tmp  .bash_history-04652.tmp  .rustup
.bash_history-04078.tmp  .bash_history-04654.tmp  .sane
.bash_history-04108.tmp  .bash_history-04655.tmp  .ssh
.bash_history-04110.tmp  .bash_history-04658.tmp  .thunderbird
.bash_history-04121.tmp  .bash_history-04659.tmp  .viminfo
.bash_history-04129.tmp  .bash_history-04662.tmp  .waterfox
.bash_history-04162.tmp  .bash_history-04665.tmp  .wget-hsts
.bash_history-04170.tmp  .bash_history-04681.tmp  .xinitrc
.bash_history-04172.tmp  .bash_history-04685.tmp  .xsession
.bash_history-04176.tmp  .bash_history-04689.tmp  .xsession-errors
.bash_history-04177.tmp  .bash_history-04693.tmp  60-qemu-guest-agent.rules
.bash_history-04181.tmp  .bash_history-04697.tmp  70-spice-vdagentd.rules
.bash_history-04187.tmp  .bash_history-04699.tmp  90-consolekit
.bash_history-04189.tmp  .bash_history-04711.tmp  Ddgr.dk
.bash_history-04199.tmp  .bash_history-04713.tmp  Desktop
.bash_history-04204.tmp  .bash_history-04727.tmp  Dockerfile.alpine.voidlinux
.bash_history-04213.tmp  .bash_history-04728.tmp  Documents
.bash_history-04214.tmp  .bash_history-04748.tmp  Downloads
.bash_history-04221.tmp  .bash_history-04758.tmp  Folli.docker
.bash_history-04224.tmp  .bash_history-04761.tmp  FreeBSD
.bash_history-04227.tmp  .bash_history-04766.tmp  Music
.bash_history-04229.tmp  .bash_history-04770.tmp  P1010005.JPG
.bash_history-04230.tmp  .bash_history-04771.tmp  P1010008.JPG
.bash_history-04233.tmp  .bash_history-04772.tmp  P1010013.JPG
.bash_history-04236.tmp  .bash_history-04773.tmp  P1010026.JPG
.bash_history-04241.tmp  .bash_history-04777.tmp  Pictures
.bash_history-04244.tmp  .bash_history-04784.tmp  Public
.bash_history-04251.tmp  .bash_history-04787.tmp  R-packages
.bash_history-04252.tmp  .bash_history-04794.tmp  Recipes
.bash_history-04253.tmp  .bash_history-04802.tmp  Rust
.bash_history-04254.tmp  .bash_history-04806.tmp  Rwork
.bash_history-04259.tmp  .bash_history-04807.tmp  Templates
.bash_history-04271.tmp  .bash_history-04811.tmp  Test
.bash_history-04274.tmp  .bash_history-04813.tmp  Videos
.bash_history-04283.tmp  .bash_history-04826.tmp  Void.docker
.bash_history-04286.tmp  .bash_history-04830.tmp  Waterfox.docker
.bash_history-04289.tmp  .bash_history-04833.tmp  Xresources.generic
.bash_history-04294.tmp  .bash_history-04887.tmp  bin
.bash_history-04309.tmp  .bash_history-04912.tmp  chkshell.sh
.bash_history-04314.tmp  .bash_history-04924.tmp  common
.bash_history-04315.tmp  .bash_history-04936.tmp  commutation.txt
.bash_history-04317.tmp  .bash_history-04986.tmp  dtest
.bash_history-04322.tmp  .bash_history-04989.tmp  fvwm
.bash_history-04323.tmp  .bash_history-04993.tmp  junk
.bash_history-04325.tmp  .bash_history-05020.tmp  junk2
.bash_history-04327.tmp  .bash_history-05085.tmp  junk3
.bash_history-04330.tmp  .bash_history-05097.tmp  libvirt
.bash_history-04337.tmp  .bash_history-05118.tmp  loader.conf.virtio
.bash_history-04344.tmp  .bash_history-05141.tmp  qemu
.bash_history-04346.tmp  .bash_history-05154.tmp  script
.bash_history-04352.tmp  .bash_history-05232.tmp  spiceubuntu
.bash_history-04353.tmp  .bash_history-05263.tmp  voidinstall.out
.bash_history-04355.tmp  .bash_history-05396.tmp  xfce-blue.jpg
.bash_history-04361.tmp  .bash_history-05440.tmp  xfce-teal.jpg
.bash_history-04362.tmp  .bash_history-05462.tmp
[nevj@trinity ~]$ 

What are all those .bash_history-*.tmp files?
Most are empty, but some contain a log of my bash commands
I have never seen that before… is it specific to Void?
I suppose the history command has to get its info from somewhere.
I think I will just remove them all

$ rm .bash_history-*.tmp

That is strange… the history command still works. Maybe it keeps the current shell history somewhere else.?
Ah yes. There is also .bash_history which is the current shell’s commands. I did not erase that.
The man page for bash mentions .bash_history but does not mention
archiving all the old histories. Maybe this is a Void feature… it does
the same with kernels… they cumulate in the boot directory.
Someday it may even be useful.

3 Likes

Hi Neville, :wave:

I don´t have such tmp files on Linux Lite, just

.bash_history
.bash_logout
.bashrc

Did you take a look at linux - Strange empty bash_history-*.tmp files in my $HOME folder - Unix & Linux Stack Exchange :question:

I haven´t read it through, so I´ve no idea if it helps.

Cheers from Rosika :slightly_smiling_face:

1 Like

@Rosika ,
Did not see that , thanks, here is the critical info

The bash source (available on Debian with apt-get source bash) writes its history file using the function history_do_write in the file bash-5.0/lib/readline/histfile.c. It creates a temporary file, writes the history lines to that, and then uses this to replace the actual history file

So if something fails, the temporary file is left undeleted.
It is not like a log file… it is not an archive.

That still seems like an aweful lot of failures. My Void does not usually
hang up on anything.

Thanks
Neville

2 Likes

Hi Neville, :wave:

Thanks for the feedback and the interpretation of the info you extracted.
That´s good to know.

O.K., I guess that´s the main thing.
Alas I don´t have an explanation for the “lot of failures” either. Curious thing.

Cheers from Rosika :slightly_smiling_face:

1 Like

Hi Rosika,
This still does not add up.
There is one .bash_history file in your home directory.
Most users would operate more than one terminal… ie more than one bash shell.
How does it keep track of the histories for multiple shells and keep them all separate?

Dont lose sleep over it
Regards
Neville

2 Likes

Hi Neville, :wave:

Yes, actually I have quite a few terminals open at any given time of my session (on different virtual desktops).

But, as I made the fish shell my default shell I very rarely make use of the bash shell.
I don´t know whether this fact would account for anything.
Just wanted to let you know…

Many greetings from Rosika :slightly_smiling_face:

2 Likes

I think the history belongs to the shell, not the terminal session. So fish should have a history file somewhere?

I dont understand how multiple shells can use the one history file?

2 Likes

Hi Neville, :wave:

yes, you´re right of course.

These are my histories:

  • /home/rosika/.bash_history
  • .local/share/fish/fish_history

Cheers from Rosika :slightly_smiling_face:

1 Like

Hi Rosika,
I have the answer

when Bash exits, it dumps the history in memory to a disk file.
 Consequently, the history file is overwritten every time we exit
 a Bash interactive login. This behavior has implications when 
we have multiple Bash sessions/terminals active because the
 HISTFILE would contain only the contents of the last exiting 
shell.

So it only saves the history of the last shell to exit… unless it is Void where those tmp files may contain all the histories I ever used.

2 Likes

Hi Neville, :wave:

thanks for the explanation.

I also found it here: https://www.baeldung.com/linux/preserve-history-multiple-windows.

It goes on to say:

However, we can enable the history append option by using the shopt builtin:

$ shopt -s histappend

We can add this command to the ~/.bashrc file to prevent overwriting HISTFILE on shell exit.

Thanks again and many greetings from Rosika :slightly_smiling_face:

2 Likes