如何永久更改历史记录大小?


69

Ubuntu中默认的历史记录大小为1000,但太小。我想将其更改为10000,所以我追加了

export HISTSIZE=10000
export HISEFILESIZE=10000

.profile 和“源”这

source .profile

然后我跑

echo $HISTSIZE
echo $HISTFILESIZE

两者均显示为1000,但我重新启动计算机后,系统显示为“默认”。为什么不起作用?


您在这里遇到一个错字:(export HISEFILESIZE=10000尽管.profile回声有效,但您似乎没有打错)。万一有人在这里看,应该是HISTFILESIZE
Leo

Answers:


71

我尝试了同样的事情,只是发现偷偷摸摸的Ubuntu ~/.bashrc默认将这些变量设置为默认值,而不是~/.profile为非登录shell(例如仅打开终端窗口)执行该变量。更改这些行~/.bashrc会为我修复:

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000

6
hisfilesize的单位是KB?
Patoshiパトシ

12
@duckx没有,HISTFILESIZE是行数存储在历史文件,而HISTSIZE是行的数量由每个shell进程存储和可用的(然后保存到HISTFILESIZE)。请注意,没有值(或非数字,或负数)时,则没有限制。
vaab 2015年

2
由于某些原因,这在XFCE终端上
不起作用

1
@MichalPrzybylowicz:/etc/bash.bashrc如果您可以接受,则可以通过书写方式进行修复。见下文。(也许也是失踪者export
serv-inc

43

从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


2

@Michal Przybylowicz所述,有时在Xubuntu(和Lubuntu)中这些文件似乎被忽略了。如果是这样,您可以改写这些行

export HISTSIZE=10000
export HISTFILESIZE=10000

/etc/bash.bashrc。这将全局更改这些环境变量的值。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.