Bash – GNU screen loses (parts of) command histories

bashgnu-screen

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.

Best Answer

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 the defscrollback num or scrollback 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.