Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

HISTCONTROL determines which commands enter Bash history, HISTSIZE limits the command entries kept in the current shell’s memory, and HISTFILESIZE limits lines in the saved history file. They work at different stages, so changing one does not make the others redundant.

What each Bash history setting controls

Setting Controls Documented default or key behavior
HISTCONTROL Which commands Bash adds to the history list Accepts colon-separated behavior options, including ignorespace, ignoredups, ignoreboth, and erasedups.
HISTSIZE Maximum number of command entries retained in the current shell’s in-memory history list 500 after startup files have been read; zero disables saving to the list, and a negative numeric value means unlimited entries.
HISTFILESIZE Maximum number of lines in the history file on disk After startup files are read, Bash sets it to the value of HISTSIZE if it has not otherwise been set. Zero empties the file; a negative or non-numeric value inhibits truncation.

The GNU Bash Reference Manual defines HISTSIZE as “The maximum number of commands to remember on the history list,” and HISTFILESIZE as “The maximum number of lines contained in the history file.” The difference matters: one counts command entries in memory; the other counts file lines. These documented defaults are starting values after startup files have been read, not guarantees about every running shell. GNU Bash Reference Manual: Bash Variables.

How HISTCONTROL filters commands

HISTCONTROL is a colon-separated list of values controlling how commands are saved on the history list. Its options affect which entries are accepted, not how many entries the list or file can hold.

  • ignorespace: skips a command line whose first character is a literal space.
  • ignoredups: skips a command if it matches the immediately preceding history entry.
  • ignoreboth: combines ignorespace and ignoredups.
  • erasedups: removes prior matching lines from the history list before saving the current command.

Leading-space filtering is only a history-list convenience. The manual describes that narrow behavior; it does not establish that the command is protected from recording by other shells, logging, or other tools. Do not rely on it as a secure way to handle secrets.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How HISTSIZE limits the current shell’s memory

HISTSIZE caps the number of commands Bash remembers on the current shell’s history list. When the list grows beyond the configured limit, older entries are discarded. Setting it to 0 disables saving commands to the list; a negative numeric value removes the entry limit.

The documented default is 500 after Bash has read its startup files. A startup file or later shell configuration can set a different value, so inspect the active shell rather than assuming that every Bash session uses 500.

How HISTFILESIZE limits the saved file

HISTFILESIZE controls the number of lines Bash allows in the history file, not the number of commands held in memory. Bash removes the oldest entries when truncating the file to meet the configured limit. Setting it to 0 empties the file; a negative or non-numeric value inhibits truncation.

Because a history entry can span multiple lines, Bash may leave the file with more lines than the nominal limit rather than truncate an entry in the middle. The limit is therefore not always a strict line-by-line ceiling.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What happens to history when Bash starts and exits

At startup

Bash initializes the history list by reading the file named by HISTFILE. If HISTFILE is unset, the default is ~/.bash_history. Bash truncates the file as needed according to HISTFILESIZE.

At exit

When history saving is enabled, Bash writes the last HISTSIZE entries from the in-memory list to the history file. With the histappend shell option enabled, it appends entries; otherwise, it overwrites the file. Bash then applies HISTFILESIZE truncation. An unset or empty HISTFILE, or a file that cannot be written, prevents saving. GNU Bash Reference Manual: Bash History Facilities.

Choose settings based on the behavior you want

Skip leading-space commands or duplicates

Set HISTCONTROL to ignorespace to skip lines beginning with a literal space, ignoredups to skip consecutive duplicate commands, or ignoreboth for both behaviors. Choose erasedups when you want an existing matching command removed from the list before the newest instance is saved.

Keep more commands in the active shell

Increase HISTSIZE to retain more command entries in memory. This setting alone does not ensure that the same number will remain in the history file: that file is governed separately by HISTFILESIZE.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Keep more history on disk

Increase HISTFILESIZE to allow more file lines. If you want a larger retained history both while the shell runs and after it exits, configure both size variables with values suited to their different units and effects.

Preserve entries from multiple shell sessions

Enable the histappend shell option if exiting shells should append history rather than overwrite the file. With the option disabled, the exiting shell overwrites the file with its saved entries. This is a separate choice from filtering commands and setting either size limit.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Inspect the active values

To see the variables and whether histappend is enabled in the current Bash session, run:

declare -p HISTCONTROL HISTSIZE HISTFILESIZE HISTFILE 2>/dev/null
shopt histappend

The first command displays variables that are set; the redirection suppresses errors for unset variables. The second reports the shell option’s current state. Startup files may set these values, so the output reflects the active session rather than only Bash’s documented starting defaults.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.