Search

screen: a console-base window manager on steroids

February 14th, 2007 edited by lucas

Entry submitted by Ico Doornekamp. DPOTD needs your help, please contribute !

GNU Screen is one of my all-time favorite Unix tools. According to the official documentation, Screen is a full-screen window manager that multiplexes a physical terminal between several processes.

So, what does that mean ? GNU Screen allows you to run multiple console based applications like editors, shells, IRC clients, newsreaders, etc, all through a single terminal. Screen allows you to switch between applications or layout multiple windows in a single terminal. One of the most nifty features is that the programs running under Screen’s control can be detached - this means they are still running, even though the actual terminal is closed. Later a new terminal can be reattached to a running screen session, even from another host!

Here’s a small demo of a typical Screen session, the true story of Bob the system administrator:

Bob connects to the server and starts a new screen session.

bob@desktop$ ssh bob@server
bob@server$ screen 

Screen displays its welcome message, and after hitting the Return key, a new shell is started.

Screen version 4.00.03 (FAU) 23-Oct-06

Copyright (c) 1993-2002 Juergen Weigert, Michael
Copyright (c) 1987 Oliver Laumann

This program is free software; you can redistribute
it and/or modify it under the terms of the GNU
General Public License as published by the Free
Software Foundation; either version 2, or
(at your option) any later version.

[Press Space for next page; Return to end.]

This shell is now running inside the Screen session. Bob starts his favorite editor…

bob@server:~$ su -
Password:
server:~# vi /etc/apache/httpd.conf 

… and does some heavy editing.

ProxyRequests On


Order deny,allow
Deny from all
Allow from 10.0.0. 

/etc/apache/httpd.conf 993,25 94%
– INSERT —

But then disaster strikes: The CEO comes in and trips over the uplink network cable, breaking the SSH session!

Disconnected;
connection lost. (Connection closed)

bob@desktop$  

Screen to the rescue! Bob starts a new SSH session to the server, and now runs Screen with the -x parameter.

bob@desktop$ ssh bob@server
bob@server$ screen -x 

Instead of starting a new session, screen now reattaches to the running screen session, and Bob finds his editor just the way he left it!

ProxyRequests On


Order deny,allow
Deny from all
Allow from 10.0.0. 

/etc/apache/httpd.conf 993,25 94%
– INSERT —

While editing, Bob decides he needs to check his mail. Instead of opening another SSH session to the server, he hits C-a C - that is, he types Ctrl-a and then ‘c’.

Screen now creates a new window, opening a new shell…

bob@server$ mutt  

…and Bob starts ‘mutt’, his mail user agent.

q:Quit d:Del u:Undel s:Save m:Mail r:Reply g:Gro
2 + Dec 22 Daniel Hirschi (0.6K) Implementing s
3 + Jan 06 Ricki Silversto (3.0K) Paycheck
4 + Jan 26 Roberto (1.0K) Read this!
5 C Jan 26 Michel Wraith (9.0K) RE: finished

—Mutt: ~/Maildir [Msgs:5 19K]—(threads/date)—(a)

With the keystrokes C-a 1 and C-a 2, Bob is now able to switch between vi and mutt, from the same console.

Time to go home. Bob hits C-a D, which will detach the current screen session from his terminal, and takes the bus home.

bob@server$ screen -x
[detached]
bob@desktop:$ logout 

After dinner, Bob decides to finish the job. From his home computer, he opens a new SSH session to the server, and reattaches to the running screen session:

bob@home$ ssh bob@server.company.com
bob@sever$ screen -x

The editor and mutt are still running, and Bob can now continue his work from home from the point he left.

ProxyRequests On


Order deny,allow
Deny from all
Allow from 10.0.0. 

/etc/apache/httpd.conf 993,25 94%
– INSERT —

Screen has been available for ages in both Debian and Ubuntu.

Posted in Debian, Ubuntu |

16 Responses

  1. Adriano Says:

    It’d be interesting to know how to close (end for good) the screen session, or is there something I’m not getting? It looks like the server always has a screen session for Bob running. It doesn’t feel “safe”.

  2. Noufal Ibrahim Says:

    I’ve been looking for a way to use something other that C-a as the control prefix for screen. Does anyone have any ideas? It conflicts with readlines default beginning-of-line and that’s something my fingers are used to.

    @Adriano
    You can end a screen session by reconnecting to it and closing the terminal running there (it says something like [screen is terminating]).

  3. Kushal Says:

    Another useful trick to play with screen: use the multiuser mode to let friends watch your game of nethack. :-)

    @Noufal:
    see the -e option to screen. Also, see Key Binding -> Command Character in the screen manual.

  4. knarf Says:

    It’s possible to give a name for each window with C-a A and list every windows (and their name) with C-a ”

    There is also a copy/paste function : C-a [ and C-a ]

  5. Ico Says:

    Adriano: a screen session is closed when the program running in the terminal exists. Just type ‘exit’ at the shell, and the session is gone

    Ibrahim: You can specify the escape key to use in a .screenrc file. I use ^W myself for the reason you stated: ^A clashes with readlines ‘begin of line’:

    escape ^Ww

  6. Michael Says:

    I use ^\ for my command character. I haven’t run into anything else that uses it yet. Of course, ‘\’ is used as an escape character within the configuration file so I have a line like this:

    escape ^\\\

    I also use the hardstatus configuration command to give me a nice status bar at the bottom of my terminal. I include server name, load, date and time, screen buffer name, and miscellaneous stuff generated by a backtick command.

    Screen is pretty much my favorite tool. I use it daily.

    Michael

  7. Juanmi Says:

    Screen is a very goog packet, have more implementations.

    Two persons, or more, can manipulate one session, imagine a teacher and the students, the teacher have permissions for “write” and the students only can “read”.

    It´s a wonderfull packet.

    Sorry for my english ;-).

  8. Kvorg Says:

    If you look through the man page, you will see that you can have named sessions and you can list (screen -ls) and wipe (screen -wipe sessionname) sessions.
    Screen is ideal for long running or persistent jobs, such as compiler sessions and rtorrent sessions.
    There is no real problem with security with normal sessions, since an intruder has to be in your account to access your sessions. However, screen allows for acl controls and shared sessions, which in a unique and very poverful feature.

    A less well-known fact is that ETerm supports screen protocol vie EScreen context and theme. This makes ETerm use tabs that are managed by as screen sessions. Ever seen your X session crash and wandered how nice it you be if you could get you 30 terminal session back? With EScreen, you can! (Perhaps this should double as an ETerm/Escreen submission proposal?) :-)

  9. Gwern Says:

    One of my favorite things to do is to use the -x option, which allows multitty display: I use it to display the same screen session in all my window manager’s workgroups; I’ve also set up my terminal so it automatically logs into my master screen session or creates it. It’s pretty neat.

  10. Robin Henricsson Says:

    Screen is simply amazing.

  11. SleepLess Says:

    Anybody know how screen can start X based application and restore (or show -x) this application via different X server (for example to start my X based icq client and show it on another computer with X server running without closing the application)

  12. Malpka Says:

    I don’t know why the author didn’t said anything about advantages of screen while using ‘full time’ applications e.g. instant managers, irc, or other processes that we wish to treat like ’semi daemons’.
    For example (maybe simple & trivial but still): i want to download whole page via wget. Normally i’d use: wget -r -l2 http://site.com & but if the site is big and we wish to see sometimes numers flying though the screen we can do it in the screen (without daemon & sign). if we want to stop watching .. we can simply detatch the screen: [C-a d] now we can do more important things oour shell . Go back to the flying characters? no problem: [screen -r] resumes working shell.

  13. Ico Says:

    Malpka wrote:
    > I don’t know why the author
    > didn’t said anything about advantages
    > of screen while using ‘full time’
    > applications e.g. instant managers,
    > irc, or other processes that we wish to
    > treat like ’semi daemons’.

    I didn’t because the article length is limited - but for me it’s the main reason to run screen as well. mutt, epic, centericq, btdownloadcurses, etc.

  14. imparare Says:

    Interesting comments.. :D

  15. llx Says:

    one of the best debian pkgs arround.

  16. John Says:

    SleepLess: screen(1) only handles terminal applications. For X11 applications, you probably want xmove(1).