screen is sometimes denounced for its bloat, usually by tmux proponents, but these features come in useful, and screen's wide availability makes it useful to learn these features.

Copying and pasting text

^A[ opens selection mode. This lets you scroll through your output and select sections by pressing enter then moving your cursor to the end of your selection and pressing enter again.

You can paste the selection by pressing ^A], which will input the previously selected text, so you can save useful snippets of a command by copying with ^A[, opening a text editor, and pressing ^A] to paste it.

Customising your caption line

If you opened multiple screens in the same session, you will see a bar at the bottom listing which screens are open. This is called the caption bar.

If you want to always see it, you need to run the caption always command.

You can either add it to your ~/.screenrc file, for it to always happen when you open a terminal, or invoke it directly on the screen command line by pressing ^A: to open the command line, then enter caption always and press enter to run the command.

Like your shell's prompt, the caption bar can be customised. This is done by entering caption string $SPEC.

There are many options possible, and referring to the screen(1) manpage is more useful than memorising them. The following example lists the number and title of all screens in the caption, and highlights the current screen in red:

caption string "%?%F%{.R.}%?%3n %t%? [%h]%?"

Screen config for complicated setups

Instead of specifying a command to run when you start your screen session, you can pass a path to a configuration file to run instead.

For example, you could put this in a config file for an irssi session:

$ cat >irssi-screen-config <<EOF
screen -t irssi irssi

With this config you can then put the following command in an appropriate place to start services, and have your computer start an irssi session in a screen session on start-up.

$ screen -D -m irssi-screen-config

You can also use the hash-bang line of a file to turn your config file into a screen script.

$ cat >irssi-screen-config <<EOF
#!/usr/bin/screen -Dm
screen -t irssi irssi

Serial console client

It is common for high-end switches and development boards to have a serial port as a back-up control interface, so when everything else is failing there's still a way to diagnose, and potentially fix a problem.

When appropriate cables have been connected, your machine will typically have added a /dev/ttyUSB0 device node to represent the connection.

Reading and writing to this device will send and recieve data along the serial port line. However, in typical embedded linux appliances the other side of the serial connection is a getty, or login console.

To communicate with this, you need a client application.

Given this article is about screen, it should come as no surprise for me to announce that screen can act as such a client.

Rather than doing screen $COMMAND, to run a command in a local tty, you run screen /dev/ttyUSB0 115200.

See the "Window Types" section of screen(1) for details about what the 115200 option is, and when you would need to change it.

This is arguably a sign of bloat, that a program about terminal multiplexing includes a serial console client, however it's convenient, as screen is widely available on Linux distros.

Filter commands

Use ^A: to open the screen command line. Enter exec COMMAND to run that command.

A sequence of !, . or : symbols before the command can be used to specify whether the input comes from your keyboard (the screen's input) or the output of the command running in your screen.

Exactly which symbols to use is a bit of a mystery, but !! replaces your shell with another program talking to the terminal. For anything else, see the screen(1) manpage.

Sending files with xmodem

xmodem is a protocol for file transfer over a serial connection.

It's old and fragile, but it's simple, so development boards sometimes have it as a fall-back for when everything else fails.

sx(1) is a tool to communicate over xmodem. It can also do the ymodem protocol by invoking it as sx --ymodem.

After opening the command line with ^A:, enter exec !! sx $FILE to send that file over xmodem.

xmodem isn't completely reliable, so it may be necessary to re-run the command.