In fact, the shell is able to read and write history without being told. You need to tell it where to save the history, however, and for that you have to set the parameter
to the name of the file you want to use (a common choice is `
‘). Next, you need to set the parameter
to the number of lines of your history you want saved. When these two are set, the shell will read
lines from
at the start of an interactive session, and save the last
lines you executed at the end of the session. For it to read or write in the middle, you will either need to set one of the options described below (
and
), or use the
command:
and
read and write the history respectively, while
appends it to the the file (although pruning it if it’s longer than
);
and
are similar, but the
means only write out events since the last time history was written.
There is a third parameter
, which determines the number of lines the shell will keep within one session; except for special reasons which I won’t talk about, you should set
to be no more than
, though it can be less. The default value for
is 30, which is a bit stingy for the memory and disk space of today’s computers; zsh users often use anything up to 1000. So a simple set of parameters to set in
is
HISTSIZE=1000 SAVEHIST=1000 HISTFILE=~/.history
and that is enough to get things working. Note that you must set
and
for automatic reading and writing of history lines to work.