Friday, 4 January 2019

linux - Can history files be unified in bash?


I routinely run multiple screen sessions on my Linux desktops and servers.


A problem with this is that when I grep through my command history, I find I issued a command in a different session, and have to detach and re-attach to get that history item.


Is it possible to 'force' the differently-updated histories from multiple sessions to all go to a central history?



Answer



There are two things you need to do:



  1. Insert the command shopt -s histappend in your .bashrc. This will append to the history file instead of overwriting it.

  2. Also in your .bashrc, insert PROMPT_COMMAND="$PROMPT_COMMAND;history -a; history -n" and the history file will be re-written and re-read each time bash shows the prompt.


EDIT: Thanks to e-t172 for the history -n trick


No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...