The basic screen commands:

ctrl-a c creates a new shell

ctrl-a n go to the next shell

ctrl-a p  go to the previous shell

ctrl-a " shows a list of all the shells.  Select a shell with the cursor keys & hit enter.

In the window list, , . move the highlighted window up or down the list.

ctrl-a ctrl-a toggles between 2 shells

ctrl-a k kill a shell.  Useful for a lot of programs that become zombies

ctrl-a H start/stop capturing to a file.  The file is named after the number of the screen shell.  Requires a keypress to clear the notification.


More advanced commands:

ctrl-a d detach the current shell, making it a daemon.  You can log out without ending it.

screen -r [daemon name] reattaches to a daemon & shows the terminal output

screen -ls shows the daemons


Splitting a screen:

The xterm scroll buffer is useless in split screen mode, but it can be useful if you're only using 11 rows.

ctrl-a shift-s splits the screen

ctrl-a ctrl-i toggle between panels.  Once in a different panel, use ctrl-a " to select a shell to show in it

ctrl-a shift-q unsplit the screen, keeping the current panel

ctrl-a shift-x unsplit the screen, keeping the other panel


Scrolling in screen:

Screen by default doesn't use the xterm scroll buffer, but has its own buffer which is intended for copying text.

ctrl-a ESC enters the copy mode

In copy mode, ? / n cause it to search for text the same as less & vi, but it doesn't show line numbers or wrap around.  g G cause it to go to the start & end.

cursor keys & pgup scroll back

ESC escapes from the copy mode.  Helas, this requires sending another keypress to clear the notification.

To erase the scroll buffer, you have to enter 2 commands with crtl-a : 

scrollback 0

scrollback 1000000

To make screen more intuitive, it must be forced to use the xterm scroll buffer by editing /etc/screenrc

This magic line should already be in /etc/screenrc & just needs to be uncommented:

termcapinfo xterm|xterms|xs|rxvt ti@:te@

The xterm scroll buffer is not swapped when changing shells.  You still have to go back to abusing the copy feature for that.  Lions used to jump around the screen program like a pro & screen's disabling of the xterm scroll buffer makes lions believe it was originally just needed on vt100's.


The /etc/screenrc file

Your biggest allies in this file are 

vbell off

Get rid of all the random flashing.

defscrollback 1000000

Create a useful scroll buffer.


Giving shells useful titles

The lion screen program has the hostname & directory of all its shells, but it doesn't do this by default.

The titles of the screens have to be customized.  In Linux, it's done by appending a kludge to print an escape sequence right before the command prompt.  It can't show the currently running program but it can show the prompt.  It takes some doing to delete all the other PS1 declarations & make sure this is the only one:

export PS1='`whoami`@`hostname`:`pwd`% '
# customize the screen title
case $TERM in
        # ESC k ESC \ tells screen to set its title

On Ubunt, it has to be appended to the end of /etc/profile & all the PS1 declarations in ~/.bashrc have to be commented out.

Since its revival in 2019, the screen program has been a game changer.  Lions spent over 20 years running the script program, loading typescript files, redirecting stderr to files & loading the files to view lengthy console output.   It was a real pane to debug programs with long console output.

Having an adjustable scroll buffer with search functionality replaced all that with much simpler commands.  It might have been a stretch to have a large scroll buffer when screen was introduced in 1987, but now the scroll buffer can easily replace a debug file. 


Over time, the bugs in screen have gotten frustrating.  Being required to send keypresses to clear the notifications about exiting from copy mode or starting a log file is a real frustration.  It also tends to silently detach at random & lose all your sessions.    Most animals nowadays use tmux which requires a completely different set of ctrl key combos to do the same thing.  It seems ctrl-a is easier to hit than ctrl-b.  If it fixes all the bugs, maybe tmux could be hacked to take screen's key combos.  Lions recommend waiting for something to replace tmux.