Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

This question already has an answer here:

I connect to a screen session. After doing some stuff I detach it. Then in history | tail I only see screen -r and previous commands and not the commands run in screen session. Basically history shows different things when screen session is running and after it is detached.

How do I make sure that the commands in screen session are appended to bash history?

Config: screen 4.0.3, bash 4.1.2

share|improve this question

marked as duplicate by Gilles, Anthon, slm, jasonwryan, rahmu Nov 9 '13 at 1:17

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    

1 Answer 1

Different shells maintain their own history in memory until it is flushed (written) to history file, which usually happens when you exit the shell, but you can override this as follows:

export PROMPT_COMMAND="history -a; history -c; history -r; ${PROMPT_COMMAND}"

This means every time a new prompt is issued (ie whenever you get through running a command), first the history is appended to the file, then it is cleared from the current shell's memory, then the current shell reloads the history from the file.

This means every shell for your account on the system, whether in screen or multiple windows or whatnot, retains and displays all command history from all other shells.

Put the line in your .bashrc, and you may want to increase your history size by adding this as well:

export HISTSIZE=5000
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.