It’s been said that there are more passwords stored in history than in /etc/shadow
– so, how do I limit the number of items in history?
Advertisement
Answer
This is controlled by the HISTSIZE and HISTFILESIZE built-in shell variables. Quoting from the documentation in man bash
:
HISTSIZE
– The number of commands to remember in the command history (see HISTORY below). 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). The shell sets the default value to 500 after reading any startup files.
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. The shell sets the default value to the value of HISTSIZE after reading any startup files.
~/.bashrc
is an appropriate place to set these values. They don’t need to be exported, since they’re internal to the shell:
HISTFILESIZE=25
…will do fine, no export
needed.