screen session has 12 open windows on it. It's been running for weeks... I know I executed an ImageMagick
convert command in one of these 12 screen windows sometime last week... is there any way I can easily search through the Bash history of all 12 instances, without closing them or running
history | grep convert in all 12 screens?
You can run
history -a; history -c in all windows to save the history. And then
history -r to refresh it.
To solve it more permanently add this to your
export PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND"
Sounds difficult. Here are a couple of methods that may work for you.
If you have process accounting tools installed (on Linux, look for a package called
acct) and the permission to use them, you can find out when and possibly on what terminal you ran
If this is unavailable or unconclusive, you can execute a
history command in each instance of bash to look for
convert commands. This will find commands that were in the history file when bash started as well.
: >/tmp/convert.history for w in $(seq 0 11); do screen -p $w -X stuff \ 'history | sed 's/^.*convert/'$w'&/" >>/tmp/convert.history '; done
$(seq 0 11)iterates over the numbers of your screen windows. Make sure to skip windows that are not currently running bash but some other process that would interpret input differently.
screen -p $w stuff …sends the following string as input to the specified window. You need the newline at the end of the string.
- The file
/tmp/convert.historywill contain a list of lines like
3 convert foo.jpg, if you ran
convert foo.jpgin window 3.
tcsh allows you to share history between sessions through use of the periodic alias.
In your .cshrc (or .tcshrc) file:
set tperiod = 60 #(or any other number. Time in minutes between refreshing) alias periodic 'history -S; echo "Syncing history"'
This will automatically execute the history command every 60 minutes. This will save history to a common history file in your home directory. To update the history more often, either lower the tperiod number, or simply execute the "periodic" command to manually refresh
Bash only writes the history when it exits, which makes this problematic at best. I've heard that zsh can share history between active sessions.