The GNU screen manual
Setup the ~/.screenrc file such that many lines of stdout are saved, because by default, screen throws away the output. Put these lines in .screenrc
defscrollback 10000
ssh to remote system
Either start a new screen session or reconnect to a prior session
screen #start new session and attach to it
screen -list #list all available session and whether attached or not
screen -dr [pid.sessionname] # connect attached session to me
screen -r [pid.sessionname] # connect detached session to me
Once you are attached to a session, never use the session command by itself, or you start yet another session. It’s easy to get confused.
Once attached to a session, you can open windows (= virtual terminals).
To create a new window and switch to it and start recording in a file everything that displays on the window:
C-a c # create window and switch to it
C-a ” # list current window numbers for use in script command below
script window-N-MM-DD-HH-MM-PURPOSE.script #save stdout in unique file name
With a screen session, to switch to a different window
C-a N # switch to window N
C-a p # switch to previous window
C-a n # switch to next window
To scroll a window, switch to it and enter copy mode (which allows scrolling using the arrow keys)
C-a ESC #start copy mode
<scroll with arrow keys, if running Terminal, can copy to clipboard>
ESC #stop copy mode
NOTE: DO NOT create another screen session from within a screen session. If you do, then follow Marco’s advice
Problem with screen w/in a screen is that there is no way to send
the C-a to the nested screen. The best way to sort out the problem
is to connect to the nested screen directly using
screen -rd <id of screen>
the ‘d’ parameter will detach the nested screen then in the other
‘nesting’ screen you will have the terminal back.