Bash HISTCONTROL, control bash history commandFollow @ggarron
Few tips to use with bash command history.
- Erase duplicates in your history file If you repeat some times the same command, like I usually do when checking memory with
- Ignore Duplicates on bash command history, if they are in a row If you set HISTCONTROL variable to ignoredups, it will not store repetitive commands in a row, but it will store dups if you do something like this.
- Control which commands are stored and which are not If you want full control over which commands will be stored by history and which will not be stored, set HISTCONTROL to ignorespace
- Ignore dups and ignore space at the same time You may set the bash variable HISTCONTROL to ignoreboth, and it will act as with ignoredups and ignorespace.
free -mYou will end up with a lot of those command repeated through your command history, and if you type
historyYou may see an output like this:
ls -l ls -h free -m free -m free -m free -m free -mIf you want to get rid of the reapeated commands, set the variable HISTCONTROL to erasedups.
export HISTCONTROL=erasedupsAnd the output of the command
990 ls -l 991 ls -h 992 free -m 993 history
ls df ls ls ls df dfYou will see the output of
1000 ls 1001 df 1002 ls 1003 df 1004 history
export HISTCONTROL=ignorespaceThis will cause that if a command starts with a space, it will not be stored in your bash history, so you can run
ps auxw df -h ps auxwAnd the output of
1015 ps auxw 1016 ps auxw 1017 history
The first one is the one I prefer, how about you?
I have already written about this here but I think now is better explained.