Using History Feature On Bash Shell On Ubuntu 16.04 LTS Server
Search the command history for “free”:
Bash Shell Variable
Location of the physical file where history stores the commands. The bash shell defaults to “~/.bash_history”. Setting “/dev/null”, will disable history recording.
Refers to a number of commands to be stored in the history file.
Refers to a number of commands that are stored in memory in a history list. Setting a value of 0 (zero) will disable history recording.
Sometimes it is required not to store some kind of commands. This variable takes a list of colon separated patterns. For example, the below configuration make history feature not to record the commands: ls, top and clear.
This HISTTIMEFORMAT variable allows displaying history with time stamp.
Having HISTTIMEFORMAT set to ‘%F %T ‘ yield the below results.
This is a very useful command for system administrators.
HISTCONTROL helps in ignoring duplicates. HISTCONTROL can be set with values: erasedups, ignorespace, ignoredups, or ignoreboth. (colon separated)Following are some examples:
Suppose the history entries contain duplicates as follows (“top” and “ls –latr” are repeated consecutively)
If HISTCONTROL was set to “ignoredups” then the history would have displayed like below:
“history -a” is used to append the history commands in memory to ~/.bash_history
“history -c” is used to clear the history commands in memory
“history -r” is used to read history commands from ~/.bash_history to memory
A typical “~/.bashrc” file with history related configuration setting will appear like below: