/ linux

Bash - increase command history size

Do you use CTRL+R shortcut in bash to search for previously used commands? I do and sometimes I can't find command because it was removed from history. Default history size is set to 1000 lines, at least on Fedora 26. It's not a small size but it's not enough for me. We can check the current settings.

$ echo $HISTSIZE

What does it mean? Let's check man bash.


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 results 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.


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.

To change those limits, edit ~/.bashrc file and add:


Apply changes.

$ source ~/.bashrc

Done. You can set another limit, I would like to test 20000 ;-)