微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

bash HISTSIZE vs. HISTFILESIZE?

HISTSIZE和HISTFILESIZE有什么区别?

它们用于扩展bash历史超过认500行。

在这里和其他论坛似乎缺乏清晰,为什么他们都需要。 (Example 1,Example 2,Example 3)。

简短答案:

HISTSIZE是在您的bash会话正在进行时在历史列表中存储在内存中的行或命令的数量

HISTFILESIZE是(a)在会话启动时在历史文件中允许的行或命令的数量,(b)存储在bash会话结束时的历史文件中,以供将来会话使用。

注意在内存中磁盘上的文件和列表之间的区别。

长答案:

所有的信息上面一些例子:

HISTFILESIZE = 10和HISTSIZE = 10

>你开始你的会话。

>您的HISTFILE(存储您的bash命令历史记录的文件)被截断为包含HISTFILESIZE = 10行。

>你写50行。
>在50个命令结束时,只有命令41到50在您的历史记录列表中,其大小由HISTSIZE = 10确定。
>你结束你的会话。

>假设histappend没有启用,命令41到50保存到HISTFILE,现在它有10个命令,它在开头加上10个新写入的命令。
>您的HISTFILE被截断为包含HISTFILESIZE = 10行。

>您现在在您的历史记录中有10个命令 – 您刚刚完成的会话中输入的最后10个命令。
>当您开始一个新的会话,您从1开始,HISTFILE为HISTFILESIZE = 10。

HISTFILESIZE = 10和HISTSIZE = 5

>你开始你的会话。

>您的HISTFILE(存储您的bash命令历史的文件)被截断为至多包含HISTFILESIZE = 10行。

>你写50行。
>在50个命令结束时,只有46到50的命令在您的历史列表中,其大小由HISTSIZE = 5决定。
>你结束你的会话。

>假设histappend未启用,命令46到50保存到您的HISTFILE,现在它有开始加载的10个命令和5个新写入的命令。
>您的HISTFILE被截断为包含HISTFILESIZE = 10行。

>您现在在历史记录中有10个命令 – 来自上一个会话的5个命令,以及您刚刚完成的会话中输入的最后5个命令。
>当您开始一个新的会话,您从1开始,HISTFILE为HISTFILESIZE = 10。

HISTFILESIZE = 5和HISTSIZE = 10

>你开始你的会话。

>您的HISTFILE(存储您的bash命令历史记录的文件)被截断为至多包含HISTFILESIZE = 5行。

>你写50行。
>在50个命令结束时,只有命令41到50在您的历史记录列表中,其大小由HISTSIZE = 10确定。
>你结束你的会话。

>假设histappend没有被启用,命令41到50被保存到HISTFILE,HISTFILE现在有了它在开始时保存的5个命令以及10个新写入的命令。
>您的HISTFILE被截断为包含HISTFILESIZE = 5行。

>你现在有5个命令在你的历史记录 – 你刚刚在刚刚完成的会话中输入的最后5个。
>当您启动新会话时,您将在HISTFILE为HISTFILESIZE = 5的步骤1处重新开始。

信息从elixir_sinari

The history “file” is not updated as you type the commands. The
commands get stored in a “list” separately (accessed by the history
command). The number of these stored commands is controlled by
HISTSIZE value. When the shell (interactive) exits,the last
$HISTSIZE lines are copied/appended to $HISTFILE from that “list”.
If HISTFILESIZE is set,then after this operation,it is ensured
that only $HISTFILESIZE lines (latest) exist in $HISTFILE . And
when the shell starts,the “list” is initialized from $HISTFILE upto
a maximum of $HISTSIZE commands.

并从man bash页面

The value
of the HISTSIZE variable is used as the number of commands to save in a history list. The text of the last HISTSIZE commands
(default 500) is saved. (…)

On startup,the history is initialized from the file named by the variable HISTFILE (default ~/.bash_history). The file named by the value of HISTFILE is truncated,if necessary,to contain no more than the number of lines specified by the value of HISTFILESIZE. (…) When an interactive shell exits,the last $HISTSIZE lines are copied from the history list to $HISTFILE. If the histappend shell option is enabled (see the description of shopt under SHELL BUILTIN COMMANDS below),the lines are appended to the history file,otherwise the history file is overwritten. If HISTFILE is unset,or if the history file is unwritable,the history is not saved. (…) After saving the history,the history file is truncated to contain no more than HISTFILESIZE lines. If HISTFILESIZE is not set,no truncation is performed.

原文地址:https://www.jb51.cc/bash/392413.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐