Table of Contents

GNU Screen

According to the GNU screen web page, screen is …a full-screen window manager that multiplexes a physical terminal between several processes, typically interactive shells. What that means is: it lets users multitask within a single console window. It provides a feature similar to the Windows Task Manager, but it has even more benefits.

Using Screen

Connecting

It couldn't be much simpler to start screen…just run the command at a console prompt.

bash-3.00# screen

At this point, my terminal is cleared and my cursor moves to the first line1). The title bar in my SSH application changes too–it normally shows the hostname I'm connected to, but now it says “screen” instead.

I'll start a top session. This will occupy my console until I press <ctrl>-c.

Normally I would need to start a second ssh connection to interact with the machine while top is running, but here's where the magic of screen begins.

Creating a New Console

Use <ctrl>-a c key combination (press and hold <ctrl> while pressing a, then release both and press c). This will create a new virtual console and place it in front of the previous screen. It will appear to be a new console with a shell prompt.

bash-3.00#

The only visible difference is that the terminal title will change if your terminal setting allow it. My title changed to ”[screen 1: bash]”. Now I can perform any tasks I need to as if the other console didn't exist. I can create up to 9 virtual consoles this way.

Switching Consoles

Having more than one virtual console is great, but you'll need to switch between them. That's easy:

<ctrl>-a ” displays a list of all consoles and select one using up/down/enter keys

This is a huge bonus for those of us who write software because we can (for example):

write code in one console

make changes to configuration files in another console

tail a log in another console

leave another console open for various admin commands

connect to another machine with ssh in another console

etc.

In other words, it helps to minimize the distractions and wasted time caused by changing directories, getting in/out of various programs like tail and top, etc.

Disconnecting and Reconnecting

Even better…a screen session remains in memory until you exit all of its consoles manually. Suppose I lost connectivity to one of my machines 2). Under normal circumstances, I would lose every window that I had open on the machine in question. But thanks to screen, that changes.

Every virtual console is stored inside my screen “session”, and that session stays in memory even if my connection is broken. So I can login again and find/reconnect to my session like this:

Aha…my screen session is named 19645.pts-0.mymachine. So I'll reconnect to it.

bash-3.00# screen -r 19645.pts-0.mymachine

And I'm back right where I was before my VPN flaked out. No lost productivity. No need to reestablish all the SSH connections that were up and running. My connectivity and processes are all right where I left them.

screen even gives me a way to disconnect from my running active session: <ctrl>-a d. I'll do this if I want to connect to another machine and run screen over there (because otherwise my <ctrl>-a keystrokes will be interpreted on my current machine).

Advanced Stuff

Renaming Consoles

You can navigate to any console and hit <ctrl>-a A (note the capital A) and you will be allowed to enter a meaningful title for the window. This is useful when you have two of the same processes running and the process name doesn't tell you what the console's purpose is. When pressing the above key combination, the last line of the current terminal will display the following:

Set window's title to:

and you should enter a meaningful name and press enter. Below is an example with three consoles that have been given meaningful names: