Ubuntu 中默认的历史记录大小为 1000,但太小了。我想将其更改为 10000,因此我附加了
export HISTSIZE=10000
export HISTFILESIZE=10000
到 '~/.profile' 并 'source' 它
source .profile
然后我跑
echo $HISTSIZE
echo $HISTFILESIZE
两者都显示 1000,但我重启电脑后它就恢复为“默认”。为什么不起作用?
答案1
我尝试了同样的事情,结果发现卑鄙的 Ubuntu 默认设置了这些变量,而不是为非登录 shell(例如只打开终端窗口)~/.bashrc
执行。更改以下几行对我来说解决了这个问题:~/.profile
~/.bashrc
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000
答案2
摘自 Bash 参考手册:
HISTSIZE
The maximum number of commands to remember on the history list.
If the value is 0,
**commands are not saved** in the history list.
Numeric values less than zero result in
every command being saved on the history list (there is no limit).
因此对于无限历史列表,制作:
HISTSIZE=(一些数字小于 0)
HISTFILESIZE
The maximum number of lines contained in the history file.
When this variable is assigned a value,
the history file is truncated, if necessary,
to contain no more than that number of lines
by removing the oldest entries.
The history file is also truncated to this size after
writing it when a shell exits.
If the value is 0,
**the history file is truncated to zero size.**
Non-numeric values and numeric values less than zero
inhibit truncation.
因此对于无限.bash_history
历史文件,设置:
HISTFILESIZE=(某个数字小于 0)
答案3
正如所提到的@Michal Przybylowicz,这些文件似乎有时会在 Xubuntu(和 Lubuntu)中被忽略。如果是这样,你可以写下这些线条
export HISTSIZE=10000 export HISTFILESIZE=10000
到/etc/bash.bashrc
. 这将全局改变这些环境变量的值。