screen… ttys as window managers (1)

You either know it (in which case you probably will not bother to read on) or you must know it (and here I come to the rescue).

Open your terminal of choice (in my OS X interface I press Command-0, which invokes quicksilver and then ‘it <ret>’, with which I get an iTerm instance). Then type

$ screen

and a help text appears, showing the usual GNU license text; press Return to continue. The screen blanks out as if you had just started your session.

You are in, this is the red pill. You will never want out.

Screen is a fully-featured ‘terminal’ window manager. With it running, your terminal ‘screen’ is a store of windows (with other shells running) where you can move from one to another, copy, paste, etc… In short, you have as many instances of a shell running in the same ‘screen’ as you want, so that you do not need a collection of ‘xterm’ or ‘rxterm’ or ‘iTerm’… windows cluttering up your tiny desktop (or, if you do not have a desktop because you are physically at a tty, you get as many terminals as you need, and can switch between them at your leisure).

Say you have ssh’d to your favorite Unix server and realize you want to read your mail and edit a file at the same time (for example, you have received a mail with an attachment you have to modify and re-attach). Problems there (well, this is a simple example, you see). Imagine there is no easy way to do this. You might say: I ssh again in another terminal and do the editing there, etc… NO WAY! Clutter, clutter, clutter.

Screen is the way:

$ ssh
[password, et...] ~ pfortuny$ screen mail

Notice the 'screen' command before mail. I get my email (mutt) window, message list etc… And now, the second piece of magic:

^a c

Which means: press Ctrl-a and then c [for ‘create’]. The mail window disappears for a simple prompt: ~ pfortuny$ 

What happened?

There are now two windows in the same session. The visible one is the last one to be created (which gets ID number ‘1’) and the other is the one with mutt running (ID nr ‘0’).

All way along, Ctr-a is the prefix for all screen commands. Specifically, Ctrl-a ? shows you a help message with all the possible key combinations.

As this is the first post on the screen, I am just showing you how to multiply your sessions inside the same terminal window, and how to switch from one to another and one of the most awesome features: copy-paste between windows.

In any case, the more you use it, the more you need it.

    Short list of comands:

  • Ctrl-a [0-9]: goto window number … (the pressed number).
  • Ctr-a c: create a new window (which gets the next available ID number).
  • Ctrl-a SPC: rotate among windows. Go from window number i to window number i+1 (or 0 if at the last one). This is specially useful when you have just two open windows.
  • Ctrl-a ?: help
  • Ctrl-a [: (open square bracket). Enter ‘Copy mode’. The cursor can be placed anywhere on the screen (using the arrow keys). Press Return to satrt copying text. Move elsewhere and press Return to copy the text between the starting point and the present one to the copy buffer.
  • Ctrl-a ]: (close square bracket). Paste the text in the copy buffer onto the active screen.

The last two commands are especially AWESOME.

Finally, to exit screen, simply Ctrl-d or logout or exit each session sequentially.



  • On 11.08.08 commandliners » Is this a tty? said:

    […] above test is not just useful but sometimes even necessary. Assume you want to automatically run screen when you log into your session. You might think of adding the following […]

  • On 12.24.08 commandliners » screen: a short list of commands said:

    […] already introduced screen in detail, I am now listing some specific commands. Recall that once a screen […]

speak up

Add your comment below, or trackback from your own site.

Subscribe to these comments.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*Required Fields