Using screen command in linux does not allow logging of command history

I have been using the screen for quite some time, and I agree, this improves my performance. But one thing that I really miss is team history. Everything that I type in a screen session is not logged in the command history. When I googled for the same, I found something related to this question: http://www.linuxquestions.org/questions/slackware-14/aliases-lost-when-using-screen-723624/

But it is surprising that in my case all the aliases are intact, and I can use them without any problems. As far as I know, opening a new screen session actually opens a new sub-shell. If this is true, can someone help me how to get the commands entered in the session to enter the command history so that if I open a new terminal / screen later, I can access the commands from the command history using CTRL + R Any solution that helps me make screen log commands in command history will be very helpful. Appreciate your time. Thanks.

+4
source share
2 answers

The bash shell is supposed to be used on the screen.

Insert two statements in ~ / .bashrc:

shopt -s histappend PROMPT_COMMAND="$PROMPT_COMMAND;history -a" 

The first command adds commands to the history file, but does not overwrite it, and the second command saves each command immediately after its execution, and not at the end of the session.

To expand on my answer, the history of each bash session that you opened is stored in memory until you log out and close the session. Then it will overwrite the bash history file. These commands will be added to the history file, and then after each command are reset to the file.

+6
source

It's easy to share a common story between sessions in Zsh and This Derek Reeve blog post explains how to do this . In short, add this to your ~/.zshrc :

 setopt share_history HISTSIZE=1000 SAVEHIST=1000 HISTFILE=~/.history setopt APPEND_HISTORY 

I also found instructions for doing the same on Bash , but I only tried this on Zsh.

+1
source

Source: https://habr.com/ru/post/1346184/


All Articles