mkaz.com home photography web dev about

[UNIX] Screen

screen is a "window" manager for the terminal. Similar in concept to tabbed browsing in Mozilla, but without the GUI. It allows you to have multiple terminal sessions open while only taking up one on your desktop.

Basics

Start a screen:

$ screen

Once you're in a screen, you can issue commands using ctrl-a (default), or you can map another key. I use ctrl-a often in the bash shell so I map ctrl-w to as my command key.

Create in .screenrc

startup_message off
escape "^Ww"

Commands

ctrl-w ctrl-c Create New Window
ctrl-w ctrl-n Next Window
ctrl-w ctrl-p Previous Window
ctrl-w 0-9 Switch to Window #
ctrl-w d Detach from current screen (it's still there)

Detaching/Reattaching
After detaching from a screen using ctrl-w d that session stays open and can be reattach to later. You can close your terminal sesssion, even disconnect if you were logged in remotely and reattach to the screen later.

You can reattach using:

$ screen -r


Tips and Tricks

Sharing Interactive Session
You can use screen to share interactive sessions, allowing people to see and type in the same shared terminal. This could be a nice way to do XP pair-programming remotely.

Try the following:

  1. Start up to two terminal sessions, A and B, via ssh, telnet or even local.
  2. In Terminal-A, start up screen:
    $ screen
  3. In Terminal-B, connect to screen already established:
    $ screen -x
  4. Now whatever you type in either terminal will show up on both. They are actual the same screen shared.

This sharing can be done a few different ways with multiple people. At work, since most of us have admin rights, we simply "su" to the other person and connect to the screen as them.

Another way is to set the permissions on your pts/tty session, location is usually in /dev somewhere depending on your *nix. Or use $ mesg y to set your tty session as writable.


Related Links:

Intro: http://www.math.fu-berlin.de/~guckes/screen/intro.php3

Good Stuff: http://palm.freshmeat.net/articles/view/581/

Tips: http://www.macosxhints.com/article.php?story=20021114055617124