Using GNU Screen
GNU Screen is a
multiplexer. For a long time I used it only for persisting an IRC terminal
session without it dying, but I entirely neglected learning how to use it for
other purposes. Later, thanks to a bad internet connection I became frustrated
when my SSH sessions kept dying, so I finally looked into how to use Screen for
Then I started mentoring new hires on my team and realized that a lot of them have never used a terminal multiplexer! So I wrote this handy dandy shortcut guide to help.
Why not tmux? Because I learned screen a long while ago, it’s super simple, and haven’t felt the need to learn yet another tool. But I think I will get around to it at some point and maybe write another handy dandy guide for myself as well.
Anyway, Screen is really easy! Here is a list of the most basic shortcuts I use on a day-to-day basis.
Ctrl-a c- “Create a new window”
Navigating between windows:
Ctrl-a n- “Next screen window in the list”
Ctrl-a p- “Previous screen window in the list”
Ctrl-a Ctrl-a- “Switch to previously used window”
Seeing all windows:
Ctrl-a "- “Full-screen selectable list of windows”
Ctrl-a w- “Full-screen non-interactive list of windows”
Ctrl-a A- “Name the current window”
Ctrl-a K- “Kill the current window”
Ctrl-a d- “Detach the current screen session”
screen -r- “Reattach screen”
Ctrl-a [- “Allows accessing scrollback buffer (limited # of lines) and marking lines for copy”
Ctrl-a ]- “Paste from marked lines in scrollback buffer.”
Ctrl-a ?- “Show a terse list of commands available while you’re in screen.”
Using Named Screens
Turns out, instead of using only 1 screen that you always
screen -rd reattach
to, you can make multiple and name them!
screen -S MyScreenName irssi- Starts irssi in a new screen called MyScreenName
screen -list- Show all screens (their names will have a unique ID number attached)
screen -rd MyScreenName- attaches back to the named screen named “MyScreenName”
What if you forgot to use -S to name your screen at start? Well, turns out you can name a screen from within the screen!
Ctrl-a :- Enters command mode in screen; from command mode you can type
sessionname MyScreenName2to rename the current screen to “MyScreenName2”
Adding your screen name to PS1
If your want your bash shell to always show what screen your on, you can make use of (2) environment variables that screen exports.
STY Alternate socket name. WINDOW Window number of a window (at creation time).