Curiosity is bliss    Archive    Feed    About    Search

Julien Couvreur's programming blog and more

Essential utility: "screen"


Screen is a command line utility that comes with lots of Unix variants (including Linux). It is a bit hard to describe and to discover. It provides two main features: multiplexing a terminal and detaching/re-attaching sessions.

I originally got shown this by my "System programming" TA, when I asked him if I could disconnect X11 application from one terminal and have them re-open (in the same state) onto another terminal. It turns out this is possible for X11 applications (see xmove or xmx, proxy-based redirections, or guiEvict <via sweetcode>, described in this paper). But "screen" although limited to text applications is so useful that I dropped my search for its X11 equivalent.

Multiplexing: If you start a remote shell (say SSH) but want to do more than one thing at a time, you may want to open more sessions, but you can also use screen. It allows you to switch between multiple shells on the same connection.
You need to first run "screen", then use "C-A C-C" (control A, control C) to create a new shell, and you now can switch between shells with "C-A C-*" where * is the number for you shell (for ex, use "C-A C-1" to switch to shell 1).

Session migration: Let's say you need to disconnect from that session, but you want to continue it from another computer. You can use "C-A C-D" to detach screen. All the shells will be maintained, and you can reconnect to the remote machine again and type "screen -R" to re-attach to the original session. This is also very useful in can the connection is lost by accident.

For more shortcuts, press "C-A ?".

Update: a similar story (with more details) was just posted on kuro5hin.

comments powered by Disqus