I issued many commands yesterday in my CentOS 7. But when I wanted to retrieve these commands today, I found there was no any record. When I opened the file .bash_history
, I still could not find the commands I issued yesterday but I found many old commands a few days ago. Why were the recent commands not stored? How can I increase the history capability?
Bash – sometimes history commands are not stored in .bash_history
bashcommand history
Related Question
- Bash – Saving bash history from multiple Konsole not working correctly
- Bash – does history not overwrite but append when histappend is set to off in Bash
- Zsh History – How to Comment Out Dangerous Commands
- Bash – Why does default bash seem to not have some of the commands I’ve used in history but does have others
- Bash – how to avoid writing failed bash commands to bash_history
- Lose the ZSH history
Best Answer
The most likely cause for history items not to show up is not by setting
HISTFILE
to nothing orHISTSIZE
to zero, it is by logging into the same machine twice and exiting with the second bash instance (in which you did little or nothing) after the one where you did a lot. By default Bash doesn't merge histories and the second Bash-exit overwrites the.bash_history
that was so nicely update by the first Bash-exit.To prevent this from happening you can append to the history file instead of overwriting, you can use the
histappend
shell option:More details in this answer including how to use
HISTSIZE
,HISTFILESIZE
andHISTCONTROL
to control size, duplicates etc.