Screen

From Dreamwidth Notes
Jump to: navigation, search

Intro

screen is a tool that's best explained as a kind of session manager for the command line. It lets you do things like:

  • disconnect from a command-line session, but still leave it (and any commands in it) running
  • reconnect to a session, even after logging out and logging in again
  • share a session with multiple people (multiuser mode), so that everybody can see what you is doing -- for instance, for teaching folks how to do something

Starting screen

You can simply run the command screen to start a new screen session. However, if you have several sessions on the go, or if you're going to have other people connecting to a session, it makes things easier if you give your screen session a name, eg

   screen -S styles-hacking


Command cribnotes

To give screen a command, first type the screen "command key". By default, it's ctrl-a.

   c       create new window 
   0-9     change to window 0-9
   ctrl-a  toggle back to last seen window 
   n       next window
   p       previous window
   "       show a list of all windows
   
   A       give the current window a name
   K       kill the current window
   ctrl-\  (or :quit) kill all windows & quit
   
   d       detach -- drop out to the shell, but leave your screen session running
   ?       help

Config

The config file for screen is called .screenrc -- find or create it in your home directory.

One of the nice things you can do is to set up screen to have a status bar on the bottom line. This shows you some useful info, but more importantly, shows that you're inside a screen session (as opposed to the usual plain command line). Example:

   hardstatus alwayslastline "%c:%s %M %d %H%? %l%? %1`"

(Yes, this is totally a bunch of gibberish. Its meaning is in the screen docs, which I will one day read through so I can explain them here.)


Multiuser Mode

Multiuser mode is great for teaching/learning how to do a complex task on the command line, or for pairing on code with someone over the internet.

To enable multiuser mode so that other people can connect to your screen sessions, add these lines to your .screenrc :

   multiuser on 
   acladd <list of users who should be able to connect>

So, for instance, on your dreamhack, you might have

   multiuser on 
   acladd dh-mark,dh-rahaeli,dh-afuna

Then, other users can connect with: screen -x yourusername/sessionname, eg

   screen -x dh-afuna/styles-hacking