bash 不保留历史

yoh*_*hbs 20 bash history

我运行 Ubuntu 12.04,由于某种原因 bash 没有保留我的命令历史记录。该~/.bash_history文件仅包含我几个月前键入的 3 个命令。

我怎样才能解决这个问题?

编辑: 这是我的相关内容.bashrc

# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples

# If not running interactively, don't do anything
[ -z "$PS1" ] && return

# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth

# append to the history file, don't overwrite it
shopt -s histappend

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000
Run Code Online (Sandbox Code Playgroud)

mah*_*ich 25

也可能是 root:root 拥有您的 .bash_history(ROOT 不应该是所有者,您的用户应该是所有者!),在这种情况下,您需要:

$ chown user:user .bash_history
Run Code Online (Sandbox Code Playgroud)

当您经常使用 sudo bash 时,这显然会神奇地发生!