Screen

August 20th, 2009

I really should use screen more.  For those not in the know, it lets you create a terminal session and then detach and reattach that session.  For example if you have a server running, running IRSSI and SCREEN lets you have a permanent connection and you can log in to that session (via your server) from anywhere.

A lot of this information came straight from IBM’s screen page, although similar instructions exist in numerous other places.

To start screen simply run ’screen’.  You may have to install it / apt-get / compile it first depending on your distro, though.  You get an exciting prompt (or possibly a theme question or similar, and then a prompt).

Lets use a silly example.  Open up a terminal and run screen.  You are now running screen on your local machine.  Run a command (lets say ‘top’) and watch the results.  Top is running, just like it would normally.  Now let’s detach the screen session and leave it running.  Ctrl+a is the ‘command’ warning to screen that the next keypress is a command, and the ‘d’ key is for detach.  So press Ctrl+a then d.  You then get sent back to your original terminal, and screen ends.  But the top command is still running.

To prove that, run screen -list to show the current screen sessions.  There should be only one.  To re-attachyou run screen -r and there is the top command again.  If you have several you can do screen -r -p <ID> where ID is the name or number of the screen session you want to resume (see the next paragraph for that).

Creating a new screen from within screen is simple, with the create command (c).  Quit from top, and do Ctrl+a then c.  Remember it will still look like a terminal so you may not know it worked.  You can list the screens by the command (“) although they are fairly non-descript.  We should name them something more useful, which we can do using the annotate (A) command and entering whatever text you want.  When you list them, it will now show their annotated names.  You could also name them when starting screen by using screen -t <name>.

One tip IBM say is to change screen to give a bottom line saying some useful information.  You can do this by editing the ~.screenrc file and adding / amending it to be:

hardstatus on
hardstatus alwayslastline
hardstatus string "%{.bW}%-w%{.rW}%n %t%{-}%+w %=%{..G} %H %{..Y} %m/%d %C%a "

Command Line Parameters (with a -)

  • r – resume
  • t <NAME> - name
  • p – used with r to pick the screen window (name or number)

Commands (start CTRL+A)

  • d – detach
  • c – create new screen
  • ” – list screens
  • a – annotate – name a screen

MORE TO COME AS I USE SCREEN MORE!

Comments are closed.