I use GNU screen
with 5 different sessions, each of which stores its own command history. But often I don't find a command in the history, although I'm sure I've used it exactly in the session I'm currently in, a few weeks ago.
It seems there is a hard limit on the history size? How can I set that to infinity?
A related question: How can I control where the history of a session is stored? Often, our sysadmin reboots the computer(s) and I lose all my sessions, and I have to do screen -wipe
because the sessions are corrupted. Then, all histories are gone. :( I'd like to find the stored histories in that case and bind them in a newly created session.
P.S.: I use bash
in all screen sessions.
UPDATE: I am not asking about how to unify the session histories. Just, I want each session to have an infinite history, and I want to be able to 'load' that history into a new session, should the old one get corrupted or deleted.
UPDATE 2: You've probably figured out: When I said I use GNU screen
with 5 different sessions I really mean a GNU screen
session with 5 different windows in it. Sorry.
You'd be better off using Bash's history than screen's. Screen keeps a scrollback buffer (probably in-memory rather than in a file). When you recall commands using Ctrl-a { it's actually digging through everything that appeared on the screen that's still in the buffer that looks like it follows a prompt character. There's not really a command history. You can increase the size of the scrollback buffer using
screen -h num
or thedefscrollback num
orscrollback num
screen commands, by the way.You can use warren's suggestion to keep your Bash history up to date. And/or you can use one of my logging functions found here that can save your IP address or screen session ID along with date, time, current working directory and actual command. I use this all the time myself. You may have to set the variable
$hcmntextra
, which is used by my functions, to include$STY
so the screen session name is logged, too.I asked a similar question on SU a bit ago: https://superuser.com/questions/37576/can-history-files-be-unified-in-
To quote the accepted answer:
here are two things you need to do:
Insert the command
shopt -s
histappend in your .bashrc. This will append to the history file instead of overwriting it.Also in your
.bashrc
, insertPROMPT_COMMAND="$PROMPT_COMMAND;history -a; history -n"
and the history file will be re-written and re-read each time bash shows the prompt.See also the
history
man pages.My preferred solution to this problem is a variation of one of the previous answers.
I like to have a separate file stored for each screen session/window combination and each file is appended each time its corresponding prompt is shown:
This creates the following history files:
If you want window {x} to always use its own history file but use the same file regardless of the screen session, you can merely leave out the STY variables:
This would create the following history files:
The command histories for each window are in memory for each bash session. You'd have to have bash write to different history files for them to persist and remain separate like you're asking.
You can do this by setting
HISTFILE
per screen session. I imagine the way to do this would be something like this in your startup file:Note that this doesn't solve the problem of updating the history file when your shells are terminated by a reboot.