Commands
General
screen -S cool | Create a new session named cool |
screen -ls | List running sessions |
screen -r [cool] | Reconnect to a detached session |
screen -d -r [cool] | Detach and reconnect to session |
Session
Windows
C-a + c | Create new window |
C-a + A | Name window |
C-a + k | Kill (unresponsive) window |
Split screen
C-a + S | Split screen horizontally |
C-a + | | Split screen vertically |
C-a + tab | next split tab |
C-a :resize 60% | Resizes the current region to take 60% of the screen |
C-a + X | Remove current split |
Copy mode
Ctrl-a + [, C-a + Esc | enter copy mode |
space bar | Set first mark/copy to buffer+exit copy mode |
C-a + ] | paste (for instance in vi) |
root@server:~# cat | sendmail leo@domain.com
To:leo@domain.com
Subject:screen clipboard
...
stuff
...
Ctrl-D
Scrool mode on/off
C-a + s | Freeze/block scrolling (feels like screen is dead) |
C-a + C-q | stop freezing mode |
Making a copy of the screen buffer to a file
To write the entire contents of the scrollback buffer to a file, type Ctrl + A and : to get to command mode, then:
hardcopy -h <filename>
Source: https://stackoverflow.com/questions/4807474/copying-gnu-screen-scrollback-buffer-to-file-extended-hardcopy
~/.screenrc
A good sample indicating time and stuff (to know when you got disconnected).
autodetach on
startup_message off
hardstatus alwayslastline
shelltitle 'bash'
hardstatus string '%{gk}[%{wk}%?%-Lw%?%{=b kR}(%{W}%n*%f %t%?(%u)%?%{=b kR})%{= w}%?%+Lw%?%? %{g}]%=[ %{=b r}%H %{= w}%Y/%m/%d %c:%s%{g} ]%{W}'
bind c screen 1
bind ^c screen 1
bind 0 select 10
screen 1
Explanations on hardstatus
%{=b kR}
% | the escape character itself |
{ | attribute/color modifier string terminated by the next } |
= | change the current attributes to the specified set |
b | bold |
k | black background |
R | red, the capitalized versions of the letter specify bright colors |
} | closing attribute/color modifier string, what comes after is affected |
Documentation: http://www.gnu.org/software/screen/manual/html_node/String-Escapes.html
Connect to a console port
screen /dev/ttyUSB0
if you need to specify the baud rate, add it after the serial device. eg, for 57600 baud:
screen /dev/ttyUSB0 57600
Control a screen within a screen (even more inception)
https://unix.stackAexchange.com/questions/29140/how-do-you-detach-the-2nd-screen-from-within-another-screen