What is the difference in HISTSIZE
vs. HISTFILESIZE
?
They are used to extend bash history beyond the default 500 lines.
There seems to
HISTSIZE
is the number of lines or commands that are stored in memory in a history list while your bash session is ongoing.
HISTFILESIZE
is the number of lines or commands that (a) are allowed in the history file at startup time of a session, and (b) are stored in the history file at the end of your bash session for use in future sessions.
Notice the distinction between file
: on disk - and list
: in memory.
All the info above + some examples:
Example 1:
HISTFILESIZE=10
and HISTSIZE=10
histappend
is not enabled, commands 41 to 50 are saved to your HISTFILE which now has the 10 commands it held at the beginning plus the 10 newly written commands.Example 2:
HISTFILESIZE=10
and HISTSIZE=5
histappend
is not enabled, commands 46 to 50 are saved to your HISTFILE which now has the 10 commands it held at the beginning plus the 5 newly written commands. Example 3:
HISTFILESIZE=5
and HISTSIZE=10
histappend
is not enabled, commands 41 to 50 are saved to your HISTFILE which now has the 5 commands it held at the beginning plus the 10 newly written commands. Info from 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.
And from the man bash
page:
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.