Penguin

Screen is an unusual and highly useful TerminalEmulator. It allows you to run interactive console programs in a Screen session that persists even if you close the terminal window or SSH session you started it in. In fact, you can later reattach to the Screen session. The programs running inside are never affected in the least.

You might f.ex start a MailClient or an IRC client inside a Screen session on a server. You can use SSH to connect to that server from anywhere and and take control of the session, never having to close the programs running inside that session. This is particularly useful if you only have physical access to a machine with a flaky connection (such as dial-up or dynamically-assigned IP) but have an account on well-connected machine. By running clients in a Screen session on that server you can avoid them dying every time you lose your connection.

You might also be interested in Xnest(1) combined with xmove(1)?, which does a similar thing for GUI apps -- xnest provides an XServer inside another XServer, and xmove can change the display of running X11 applications - ie redirect them to another X server.


Useful tips

  • You should really read the screen(1) ManPage -- the program is chock full of useful bits.
  • screen -rx allows to to attach to an existing screen session, even if you are already attached to it from another terminal.
  • If you use Ctrl-A a lot and don't like screen catching this, you can change the key used for this by adding escape ^ss or similar to ~/.screenrc. The first character, ^s defines the escape char, the second character is what you press after an escape to send a literal escape sequence.
  • The documentation is not quite clear on how to launch processes into new windows in a running Screen session. The -m -d switch combination advertised for launching processes in detached mode creates an entire session for each of them. If you want them running in an existing session, you have to send that session the screen command. Sending commands to a session from the Shell is done by invoking screen -X command. Effectively, this means that you launch a batch of wget(1) downloads in a screen session by invoking screen -X screen wget $someurl in a loop.
  • If you su to a user (because you can't SSH/login as them directly, ie "I am stealing their IRC session") and then get a message like "Cannot open your terminal '/dev/pts/7' - please check", you need to change the permissions on your terminal before the su, so you can write to it from the new user: chmod 666 `tty`.
  • If you would like to send commands to a screen session inside another session you can run into issues, as the first screen will capture the commands. To pass a command to the inside session first do C-a a this does a literal C-a, passing it to the inside screen session, or any other application you need to pass C-a to. IE to detach from the inside session C-a a d.

hardstatus

This line enables you to have a constant display of what windows are open, to make switching between them faster. Check the 'STRING ESCAPES' section of the screen man page for information on how to build your own one. The one BenStaz uses can be seen below. To try it out, simply paste these lines into ~/.screenrc.

hardstatus alwayslastline
hardstatus string "%{.bW}%?%-Lw%?%{.rW}%n*%f %t%?(%u)%?%{-}%?%+Lw%? %= %D %d/%M/%Y %C:%s%a"

Links: