我的 $HOME 文件夹中出现奇怪的空 bash_history-*.tmp 文件

我的 $HOME 文件夹中出现奇怪的空 bash_history-*.tmp 文件

我的主文件夹中恰好有 169 个空文件夹,.bash_history-*.tmp这些文件夹是在我不知情的情况下于同一天(2021 年 4 月 16 日)创建的。文件只有所有者的读写权限。我不确定是什么导致了这种情况的发生。在我 5 年的 Linux 之旅(桌面和服务器)中从未发生过这种情况。更奇怪的是,我的默认 shell 不是 bash 而是zsh.如果有人能帮助我弄清楚到底发生了什么(如果可能的话)或者以前发生在其他人身上,那就太好了?先感谢您。这里是

.-(~)(user@host)
`-->> find . -name '.*.tmp'
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-01407.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-01810.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-02487.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-03675.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-08255.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-08260.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-08283.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-08326.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-08434.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-08450.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-08550.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-08581.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-08649.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-08676.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-08683.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-08697.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-08698.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-08712.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-08717.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-08742.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-08743.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-08819.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-08841.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-08878.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-08884.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-08904.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-08914.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-08962.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-09060.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-09116.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-09157.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-09201.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-09212.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-09228.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-09247.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-09248.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-09265.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-09274.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-09283.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-09331.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-09366.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-09397.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-09445.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-09501.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-09507.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-09548.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-09597.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-09632.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-09701.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-09760.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-09904.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-09992.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-10059.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-10158.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-10166.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-10170.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-10320.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-10536.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-10594.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-10631.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-10714.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-10753.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-11127.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-11189.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-11494.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-11514.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-11697.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-11774.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-11827.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-11973.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-12002.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-12266.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-12316.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-12331.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-12357.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-12377.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-12393.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-12399.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-12400.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-12405.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-12413.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-12417.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-12435.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-12475.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-12513.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-12563.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-12644.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-12648.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-12656.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-12743.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-12779.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-12801.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-12803.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-12817.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-12868.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-12971.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-13005.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-13013.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-13020.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-13033.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-13042.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-13047.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-13065.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-13074.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-13089.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-13090.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-13092.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-13094.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-13097.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-13099.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-13145.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-13162.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-13184.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-13202.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-13203.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-13206.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-13208.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-13218.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-13219.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-13220.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-13250.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-13313.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-13316.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-13320.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-13322.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-13323.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-13341.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-13360.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-13388.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-13489.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-13530.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-13566.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-13575.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-13576.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-13630.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-13640.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-13675.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-13717.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-14153.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-14156.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-14167.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-14204.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-14254.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-14256.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-14265.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-14267.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-14331.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-14332.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-14359.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-14368.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-14693.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-14792.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-14922.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-14923.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-14928.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-14931.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-14933.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-14943.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-14947.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-14951.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-14955.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-14968.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-30961.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-31005.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-31110.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-31142.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-32057.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-32358.tmp
-rw-------   1 user user   0 Apr 16 17:40 .bash_history-32434.tmp

仅供参考:有人帮我找到了类似的帖子archlinux论坛但它没有回答我的问题。

答案1

源代码bash(在 Debian 上可用)使用文件中的apt-get source bash函数写入其历史文件。它创建一个临时文件,将历史行写入其中,然后用它来替换实际的历史文件history_do_writebash-5.0/lib/readline/histfile.c

tempname = (overwrite && exists && S_ISREG (finfo.st_mode)) ? history_tempfile (histname) : 0;
output = tempname ? tempname : histname;

...

if (rv == 0 && histname && tempname)
  rv = histfile_restore (tempname, histname);

在许多地方写入可能会失败,在这些情况下,临时文件将被取消链接(删除),原始文件将被保留。

但是,您在路过的评论你发动了叉子炸弹。这很可能是这些临时文件的根本原因。由于不受控制的 forkbomb 触发了极端的内存和进程压力,有可能bash无法获得足够的临时内存来完成此恢复过程,并且在尝试更新期间简单地崩溃了。 (请注意,这不是铁证,只是一个假设。)

如果您处于用户可能会运行 forkbomb 的环境中,那么这是值得的启用资源控制

答案2

不可能肯定地说,但很可能有些东西改变了HISTFILE环境变量,然后调用 bash (或者可能是其他一些readline基于文件,但问题是为什么$HISTFILE会包含.bash-history)。

这听起来像是您在单元测试(套件)中要做的事情。

我已经研究了 bash 源代码几分钟了,看起来没有任何地方会偏离默认值,$HOME/.bash_history除非通过HISTFILE.

答案3

这是搜索中出现的 SO 帖子,所以我将答案放在这里。

这很可能是超过的结果$HISTSIZE

要设置为 20,000 个条目,请将其放入您的.bashrc

export HISTSIZE=20000

要使无限留空:

export HISTSIZE=

相关内容