BASH History Control
The standard output of the “history” command will show you the last one thousand commands executed by the user. This is useful, of course, but there are a few issues. Sometimes it’s important to know when a particular command was executed and the default history format does not provide this information. Can’t really call it “history” without dates. Another issue is duplicate and redundant commands in the history: you don’t really need to now the user ran the “ls” command ten times in a row, do you?
The format of BASH command history is controlled by the .bashrc file. Below are the recommended settings for the BASH history. Keep in mind that these settings are not retroactive: they will only apply to the commands you run after making this change. Thus, don’t expect to see accurate timestamps for commands you ran at some point in the past.
export HISTTIMEFORMAT='| %F %T | ' export HISTSIZE=10000 #export HISTCONTROL=erasedups export HISTCONTROL=ignoredups export HISTIGNORE="uname:uname *:whoami:ls:ls *:pwd:df:df *:grep *:cat *:tail *:history" shopt -s histappend
For the HISTCONTROL option you have two choices: to erase duplicates or to just not display them. The HISTIGNORE setting controls the list of commands that will not be displayed when you run the “history” command. Knowing these commands were executed at some point in the past gives you no practical information and clutters the output of the “history” command.