← Journal · Archiv

Lovely GNU Screen

December 21, 2005

A thousand windows open, two monitors because the space runs out otherwise, no Exposé on Windows, and a dozen PuTTYs open to various servers - now just don't lose track (dramatized).
With GNU/Screen I can open several ttys inside one tty. Put in terms for Windows folks: I open an SSH connection in PuTTY, start GNU/Screen and can then jump back and forth between several shells. Naturally you can also run programs in there that you really ought to have open all the time anyway. mutt and top, for instance.
The real killer feature is that I can also detach GNU/Screen and log out of the system. The programs keep running in the background. When I log in again from wherever, I can pull the session back.
You start GNU/Screen with

lemming@deepthought:~ $ screen

After that, something like the following appears

Screen version 4.00.02 (FAU) 5-Dec-03

Copyright (c) 1993-2002 Juergen Weigert, Michael Schroeder
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.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along withthis program (see the file COPYING); if not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA  02111-1307, USA.

Send bugreports, fixes, enhancements, t-shirts, money,
beer & pizza to [email protected]

             [Press Space or Return to end.]

Just hit Enter to continue. Now you have another shell open. This is a window (a “screen”); you open a further screen with a further shell using the key combination CTRL+a followed by c. You can jump back and forth between the two screens with CTRL+a followed by CTRL+a again. AFAIK you can open an infinite number of screens. You get to the first screen with CTRL+a 0, to the second with a 1, and so on.
You close a screen simply by ending the shell with exit, logout or CTRL+d. You then land in the next screen, or, if no window is left, GNU/Screen quits.
There are a multitude of ways to control the windows:

Ctrl+a enters command mode for GNU/Screen.
Ctrl+a c         create a new window
Ctrl+a 0         switch to window number 0
Ctrl+a 9         switch to window number 9
Ctrl+a n         jump one window forward
Ctrl+a h         jump one window back
Ctrl+a a         switch to the last active window
Ctrl+a A         name the window
Ctrl+a '         enter the name of a window to jump to
Ctrl+a "         show a list of all windows
Ctrl+a Ctrl+d    detach GNU/Screen, it keeps running in the background
Ctrl+a h         write a hardcopy to hardcopy.n
Ctrl+a H         log the window contents to screenlog.n
Ctrl+a ?         show a short overview of the keyboard shortcuts

As described above, GNU/Screen can also be detached and reattached later. This is done with CTRL+a d.
A detached GNU/Screen can be brought back with the following command.

lemming@deepthought:~ $ screen -r
There are several suitable screens on:
        19802.pts-3.deepthought (Detached)
        19823.pts-3.deepthought (Detached)
Type "screen [-d] -r [pid.]tty.host" to resume one of them.

However, it may well be that several screens are detached. So you have to be more specific and pass along the PID.

screen -r 19802

GNU/Screen is available on almost every platform, even on Windows with Cygwin. On most Linux derivatives and Mac OS X, GNU/Screen comes preinstalled. On FreeBSD and OpenBSD you can find GNU/Screen in /usr/ports/misc/screen and install it from there.
This program is a real help when you start processes that are supposed to run in the background; don't want to see a dozen terminals on your desktop; or want a log of what went on in the tty.
Small tip: su, fg and bg work flawlessly in GNU/Screen.

noledge · · 3 Views ·

wunderbares tool, ich kann ohne nicht mehr leben.

hab in der arbeit in einer screen-session verbindungen zu allen wichtigen servern und auch sehr wichtig - zum irc. damit bin ich immer online und kann in der arbeit/zuhause/unterwegs einfach hinverbinden.

noch was praktisches - wenn man beim verbinden “screen -x” ausführt, muss man bei einem anderen offenen nicht detachen - multiheadbetrieb. ich verwende es nur so. sehr praktisch vorallem daran - jeder “head” ist eigenständig in so fern, welches “fenster” (in der gleichen screen-session!) gerade angezeigt wird.

vielleicht hilfts ja jemanden

rikman · · 3 Views ·

JA, ich nutze screen auch schon seit Ewigkeiten und kann nicht mehr ohne
Besonders schoen ist die Moeglichkeit, mittels .screenrc im $HOME fast beliebige Shortcuts festzulegen, z. B. macht bei mir CTRL-A,m ein mutt-ng auf oder CTRL-A,t ein htop. Schneller gehts nicht.

Ja und weiterhin sehr schoen ist natuerlich die Moeglichkeit, so ganz schnell an eine Root-Shell zu kommen ohne jedesmal ein Password eingeben zu muessen. Ich mache einfach ein screen auf dem Server, tippe “su -” und hab meine root-Shell. Aus der brauche ich mich nicht mehr auszuloggen und beim naechsten Reattach ist die root-Shell (neben den anderen Feld-, Wald- und Wiesenshells) immer noch da. So habe ich auf den wichtigen Servern immer quasi sofort root-Permissions, wenn ich sie brauche.

Zum Wechseln zwischen den einzelnen ttys habe ich mir F11 und F12 belegt: F11 geht eine zurueck, F12 eine vor. Dabei ist das Wechseln so eingestellt, dass nach der letzten automatisch wieder die erste angesprungen wird. Und vice versa.

lemming · · 3 Views ·

Dürfen wir deine .screenrc mal sehen? Da kann man deinen Erzählungen nach viel abguggen.

Btw. Auch dir, Rikamn, ein allerschärfstes Willkommen.

rikman · · 3 Views ·

Na ja, so viel wirst du da auch nicht sehen. Ich habe die screenrc mal in das Download-Directory kopiert:

http://rikman.mtb-news.de/download/linux/screenrc

Ich hoffe, es hilft ein wenig.

martzell · · 3 Views ·

Bei meinem Breitbild-TFT (ca. 1200×900?) hatte ich unter Windows die Taskleiste an den rechten Bildschirmrand gelegt. Der Schnellstartleiste, mit eingeblendeten Symbolbeschriftungen, gab ich die halbe Bildschirmhöhe, damit ein Klick genügt um Programme zu starten. Die restliche Hälfte belegten die laufenden Programme.

Dadurch gewinnt man den immer breiter gebauten Bildschirmen nutzen ab, da man sonst von der Breite nichts hat, da die meisten Anwendungen nur nach Höhe gieren.

Angels · · 3 Views ·

Expose-Clone für Windows: http://www.winplosion.com/ und ein schönes Screen-”Addon”: http://pubwww.fhzh.ch/~mgloor/screenie.html . Jetzt gehe ich ins Bett

H. Heigl · · 3 Views ·

Hmm, der Mittelteil kam mir irgendwie bekannt vor… deshalb hab ich mal nachgeschaut und fand unter http://f0rked.com/articles/irssi einen schönen Artikel, der das Zusammenspiel von screen und irssi beschreibt.

Leave a comment