I'm often looking in my .bash_history file to see how I ran a program or exactly what arguments I used. The problem is that my history seems very incomplete. Some commands I'll find that I ran months ago, others I ran yesterday and aren't there. I think the issue is that I work over ssh a lot, and I'll often not log out cleanly, but rather be disconnected when my laptop sleeps or I move to a different wifi network. So it seems like bash only writes to the history file when it's exiting. Is this right? Is there a way I can force it write every command, or every few commands?
Add history -a
to your PROMPT_COMMAND
to update your saved history before each prompt.
PROMPT_COMMAND='history -a'
This should go in your .bashrc
file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With