Setting Shell History Options
Problem
You’d like more control over your command-line history.
Solution
Set the $HIST* variables
and shell options as desired.
Discussion
The $HISTFILESIZE variable
sets the number of lines permitted in the $HISTFILE. The
default for $HISTSIZE is 500
lines, and $HISTFILE is
~/.bash_history unless you are in POSIX mode, in
which case it’s ~/.sh_history. Increasing $HISTSIZE may be useful, and unsetting it
causes the $HISTFILE length to be
unlimited. Changing $HISTFILE
probably isn’t necessary, except that if it is not set or the file is
not writable, no history will be written to disk. The $HISTSIZE variable sets the number of lines
permitted in the history stack in memory.
$HISTIGNORE and $HISTCONTROL control what goes into your
history in the first place. $HISTIGNORE is more flexible since it allows you to specify patterns to decide
what command lines to save to the history. $HISTCONTROL is more limited in that it sup-ports only the few keywords listed
here (any other value is ignored):
ignorespaceCommand lines that begin with a space character are not saved in the history list.
ignoredupsCommand lines that match the previous history entry are not saved in the history list.
ignorebothShorthand for both ignorespace and ignoredups.
erasedupsAll previous command lines that match the current line are removed from the history list before that line is saved.
If $HISTCONTROL is not set, or does not contain any of these keywords, all commands are saved to the history ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access