Using "Screen"

Posted Wednesday, March 23rd 2011 in FreeBSD, Linux - Permalink

screen is a GNU command-line utility that lets you spawn multiple virtual terminals in a Unix environment. One really handy feature is that you can spawn a screen session through an ssh session, execute a program, log out of the ssh session, and log back in, to find your program running all the while!

To start a screen session, use

% screen

This starts one screen session. The important meta key for screen is Ctrl-a, which will let you enter commands. The following is a synopsis of some basic commands:

Ctrl-a c – Create a new screen virtual terminal.
Ctrl-a k – Kill the current screen terminal.
Ctrl-a d – Exit the current screen terminal without killing it. It keeps running in the background.
Ctrl-a – Enter the corresponding screen virtual terminal.

If you have a screen session lingering, you can enter it from the command line by using

% screen -r

If you have multiple screen sessions running, it will give you a list of detached sessions. Enter the ID of a session to enter it. For example,

% screen -r
There are several suitable screens on:
	16708.pts-0.lenovo	(03/23/2011 09:20:09 PM)	(Detached)
	16285.pts-0.lenovo	(03/23/2011 08:43:34 PM)	(Detached)
Type "screen [-d] -r [pid.]" to resume one of them.

You could then type

% screen -r 16708

to rejoin the first screen session.

Another great feature of screen is that you can tile multiple screen sessions. To split the terminal into two screen sessions vertically, type Ctrl-a S (i.e., Shift-s). You can switch back and forth using Ctrl-a Tab. If you would like to split horizontally instead, use Ctrl-a | (i.e., Shift-\). You can split windows as many times as you would like in either direction. When you want to “un-split,” use Ctrl-a X (i.e., Shift-x) to kill the current tile.

Happy screening!

List Posts Newest Posts Page 1Next Page