如何永远改变历史大小?

Mit*_*xys 102 command-line

Ubuntu 中历史记录的默认大小是 1000,但它太小了。我想把它改成 10000,所以我追加

export HISTSIZE=10000
export HISEFILESIZE=10000
Run Code Online (Sandbox Code Playgroud)

.profile 和“源”这

source .profile
Run Code Online (Sandbox Code Playgroud)

然后我跑

echo $HISTSIZE
echo $HISTFILESIZE
Run Code Online (Sandbox Code Playgroud)

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

Pau*_*aul 92

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

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

  • @duckx 不,HISTFILESIZE 是存储在历史*文件*中的*行数*,而HISTSIZE是每个shell进程存储和可用的*行数*(然后保存到HISTFILESIZE)。请注意,如果没有值(或非数字或负数),则不会发生限制。 (16认同)
  • hisfilesize 以 KB 为单位? (6认同)
  • 由于某种原因,这在 XFCE 终端上不起作用 (2认同)

Pai*_*ser 57

来自 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). 
Run Code Online (Sandbox Code Playgroud)

所以对于一个无限的历史列表,使:
HISTSIZE=(some number less than 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. 
Run Code Online (Sandbox Code Playgroud)

所以对于一个无限的.bash_history 历史文件,制作:
HISTFILESIZE=(some number less than 0 )


ser*_*inc 8

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

export HISTSIZE=10000
export HISTFILESIZE=10000
Run Code Online (Sandbox Code Playgroud)

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

  • 您的两行可以减少为“HISTSIZE=10000”,因为“.bashrc”中的 Bash 变量不需要“export”,而且如果未设置“HISTFILESIZE”,它将从“HISTSIZE”获取其值。来自 [`man bash`](https://www.gnu.org/software/bash/manual/bash.html#index-HISTFILESIZE):“shell 在读取任何启动文件后将默认值设置为 HISTSIZE 的值”。 (2认同)