1

In my home directory, I have lots of these ./.bash_history-[xxxxx].tmp files. Why?

./.bash_history-02865.tmp
./.bash_history-24895.tmp
./.bash_history-51442.tmp
./.bash_history-03847.tmp
./.bash_history-37643.tmp
./.bash_history-24872.tmp
./.bash_history-53376.tmp
./.bash_history-04725.tmp
./.bash_history-14612.tmp
./.bash_history-35739.tmp
./.bash_history-26709.tmp
./.bash_history-39963.tmp
./.bash_history-04611.tmp
./.bash_history-44124.tmp
./.bash_history-07238.tmp
./.bash_history-51292.tmp
./.bash_history-16780.tmp
./.bash_history-15855.tmp
./.bash_history-41194.tmp
./.bash_history-37322.tmp
./.bash_history-36114.tmp
./.bash_history-22629.tmp
./.bash_history-50584.tmp
./.bash_history-38343.tmp
./.bash_history-02413.tmp
./.bash_history-03914.tmp
./.bash_history-60707.tmp

Some of the files are empty. Others are very clearly bash history. My .bashrc shows HISTSIZE and HISTFILESIZE. I see no HISTFILE.

I use xfce4-terminal, version 1.1.3. Xubuntu 24.04.2 LTS.

J. Mini
  • 190

2 Answers2

2

Those files are created by Bash as mentioned in the comment by @steeldriver.

It's how Bash works ... It uses a temporary file for history momentarily.

From the source code for Bash 5: Please see around here for the name format and below here for the mechanism.

That's how it is intended and should work under ideal situations ... But suppose "meanwhile" Bash crashed, file access was denied/restricted, not enough memory (although tiny amount needed), you put your machine to sleep and power source was interrupted or ran out ... etc. You see now why you're seeing those files (each one of them is a result of similar less than ideal situations).

You also see now that those files (although some might contain data i.e. history lines) are not used or needed beyond what's meant for them in the source code.

Raffa
  • 34,963
0

The bash_history-xxxxxx.tmp files that appear on your computer are not something Bash creates by default.

Therefore, among many other causes, it is likely that these files are being generated by:

A script, program, or auditing tool.

They are related to some type of failed backup of your history.

They are caused by an error in a custom configuration.

You could investigate whether:

Your ~/.bashrc or ~/.bash_profile files contain something related to:

export HISTFILE=~/bash_history_$(date +%s)

If you have any automated scripts or cron jobs that manipulate bash_history.

You usually use multiple terminals at the same time. If so, Bash, by default, saves the history only when you exit the session. If multiple sessions are active at the same time and share .bash_history, there may be conflicts.

If you want to know more precisely how these files are being created, you can use inotifywait:

sudo apt update
sudo apt install inotify-tools
inotifywait -m ~ --format '%w%f %e' -e create

This will inform you in real time which process is creating these files.

kyodake
  • 17,808