Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make bash_history update more often?

Tags:

bash

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?

like image 429
Colin Avatar asked Oct 18 '25 10:10

Colin


1 Answers

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.

like image 132
chepner Avatar answered Oct 19 '25 23:10

chepner