Control Bash History

[[ -f ~/.bash_exports ]] && . ~/.bash_exports
export HISTSIZE=1000
export HISTFILESIZE=3000
export HISTCONTROL=ignoreboth:erasedups
export HISTIGNORE="history"
export HISTTIMEFORMAT="%F %T "
  • HISTSIZE and HISTFILESIZE control how many history entries there will be
  • HISTCONTROL gives you control over what gets stored in history; ignorespace will ignore commands that start with a space, ignoredups will not store duplicate if a command is the same as the immediate previous command, ignoreboth is a combination of the previous two values, and erasedups causes all previous lines matching the current line to be removed from the history list before that line is saved
  • HISTIGNORE means that commands in this list (separated by a colon) will not be included in history
  • HISTTIMEFORMAT means that time information can be stored alongside commands in history; the time is saved in ~/.bash_history on lines starting with # and is displayed in a format specified in this variable when using $ history command
$ !grep
$ !-1
$ !!
$ sudo !!

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store