Useful Bash History Settings
This post aims to describe some useful bash history settings, that are all too often unknown of. Following are some environment variables described, which can be set in the users bashrc file in eg.
||Do not record if line starts with a blank/space|
||Do not record line if its a duplicate of the previous line|
||Do remove all occurences of line before saving line|
The settings can be combined by colons, eg.
: separated list of patterns. Patterns may include special
* is a wildcard match, please note that matching a whole line is not implied at the end of your patterns.
You must explicitly set
& matches the previous line in the history.
Escaping can be done via double backslashes, eg
HISTIGNORE=cd *:ls *:&
The amount of lines to save in the history. This defaults to
The path where the history is stored. Defaults to
Condensing the History
My favorite history setting is to condense the history instead of using it as a log of consecutive commands.
~/.bashrc or system-wide in
HISTCONTROL='ignorespace:erasedups' HISTIGNORE='cd *:ls *' HISTSIZE='1000000'
Deactivating the History
Some hackers use this trick to not get commands logged.
Useful History Commands and Key Combinations
|Command or Combination||Description|
||Append current shell instance in-memory history to the history file|
||Reverse search the history. Press enter for execution of command|