In bash, by default, the history commands are recorded in ~/.bash\_history. You can specify a different file other than ~/.bash\_history by using the environment variable HISTFILE. The number of commands to be remembered in the history can be specified by the environment variable HISTSIZE. For example, add the following line to your .bashrc:
Then exit the current shell and launch a new one. The number of history commands to remember will be changed to 1000.
HISTSIZE V/s HISTFILESIZE
The difference between HISTSIZE and HISTFILESIZE is that HISTSIZE limits the number of commands shown by the command history while HISTFILESIZE limits the number of commands which can be saved in $HISTFILE.
When one exits the bash if there are more than $HISTSIZE number of commands which have been executed in the single bash session, the contents of $HISTFILE will be replaced by the $HISTSIZE number of commands. If there are less than or equal to $HISTSIZE number of commands in the bash session, these commands will be appended to $HISTFILE as long as $HISTFILESIZE permits.
If the number of commands to be appended to $HISTFILE plus the current existing number of commands in $HISTFILE is greater than $HISTFILESIZE, the oldest commands in $HISTFILE will be removed to ensure the latest commands are kept. One can also run the following command to force to append the history commands to $HISTFILE even though there are more than $HISTSIZE number of commands which have been executed in the bash session:
$ shopt -s histappend
For more details, please refer to the bash manual page with the following command:
$ man bash
When the shell starts up, the history is initialized from the file named by the HISTFILE variable (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 the HISTFILESIZE variable. When an interactive shell exits, the last $HISTSIZE lines are copied from the history list to the file named by $HISTFILE.
If the histappend shell option is set, 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.