Is it possible to set a fixed number for the "history" command to only show a certain amount of history items like 100, instead of everything from the beginning of time?
Is it possible to set a fixed number for the "history" command to only show a certain amount of history items like 100, instead of everything from the beginning of time?
history n
prints onlyn
lines of the history. For example:So we can make an alias in your
.bashrc
:From
help history
:This is useful if you want to keep a large history set, maybe even an unlimited one. With
HISTCONTROL=ignoreboth:erasedups
and reverse incremental search, it's a special occasion when you actually run thehistory
command.Setting
HISTFILESIZE
andHISTSIZE
you can restrict the size of history command.For example
HISTFILESIZE=100
andHISTSIZE=100
. It will restrict history file to store 100 lines andHISTFILE
which stores your cureent session command in memory to 100 lines.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 ofHISTFILE
is truncated, if necessary, to contain no more than the number of lines specified by the value of theHISTFILESIZE
variable.You can add
HISTFILESIZE=100
andHISTSIZE=100
in your~/.bashrc
file . Change the 100 with the number you want.Explanation
HISTFILESIZE=10
andHISTSIZE=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.HISTFILESIZE=10
andHISTSIZE=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.HISTFILESIZE=5
andHISTSIZE=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.This great explanation from:stackoverflow.com