More History for Linux Bash
30 Jun 2016If you open Multiple sections of Linux terminal, only one copy of history will be saved in your .bash_history file. This would be really annoying because you will forget and loose important command that you have used.
Here is how to save all your histories.
Put the following commands in your ~/.bashrc file or your ~/.bash_profile file.
# append instand of overwrite across sections
shopt -s histappend
# write and read history file every time you hit return
PROMPT_COMMAND='history -n;history -a'
# increase your history entries and file size
HISTSIZE=100000
HISTFILESIZE=100000
# add date and time information for each entry
HISTTIMEFORMAT="%m/%d/%y %T "
Sometimes you want to ignore some test commands or commands includes passwords in your history records. Here is how to do that:
# igore commands start with a space
HISTCONTROL=ignorespace
You may also want to ignore duplicated entries
# igore duplicated commands
HISTCONTROL=ignoreredups
To ignore both of them, you can do either ignorespace:ignoreredups
or
ignoreboth
.
The complete list of commands to be added in ~/.bashrc is:
# append instand of overwrite across sections
shopt -s histappend
# write and read history file every time you hit return
PROMPT_COMMAND='history -n;history -a'
# increase your history entries and file size
HISTSIZE=100000
HISTFILESIZE=100000
# add date and time information for each entry
HISTTIMEFORMAT="%m/%d/%y %T "
# ignore commands started with space and duplicated entries
HISTCONTROL=ignoreboth