Thursday, July 06, 2006

Screen is the Answer

The question is "How can I make my command line life easier in linux (and other unix style os')?"

Screen is the answer, but it is the answer even if you aren't asking the question. Screen is so fundamentally useful that should be a fundamental part of the kernel if you ask me.

So what is it? So there you are, connected to your linux box, and you kick of a compile. Before you know it, there a zillion dependencies to consider and it is going to be there a while. So now your session is tied up, so if you want to get on with something else, you need to make a new connection to the box. But what if you need to restart the machine you are connecting from while a day long compile is taking place? Killing your connection to the linux server will kill any processes associated with that session.

Or what if you want to try something in one session and see the output in another session? SecureCRT is a great ssh client, and version 5 supports tabs, which is cool. But of course each time you need make a new session, you need to authenticate.

Anyway, "screen" is the answer, as you already know because I told you at the start.

What screen does is decouple the console session from the console itself. When you create an ssh session, you are providing an input/output tty. So that you can tell the box what to do, and it can talk back to you.

What screen does is provide a proxy for that session. So screen is where your input and output go to, and you can either be connected to screen or not. When you are running screen it is transparent, it is just like you are carrying out a normal session.

But if you close your ssh session, and then reconnect from another terminal, typing screen -r will let you carry on where you left off. And it doesn't matter whether that is another ssh session, or a telnet session, or if you walk up to the physical console.

So thats useful right? But this isn't all of by a long stretch. screen isn't limited to one console session. You can have a number of them. You could have 10 different sessions going to your linux box simultaneously and then disconnect them all and resume them all somewhere else.

screen is controlled with the ctrl-a meta by default, and here are a bunch of useful commands:

ctrl-a c Create and enter a new screen
ctrl-a n Switch to next screen
ctrl-a p Previous Screen
ctrl-a " List screens
ctrl-a M Monitor screen for activity (will bell other screens if something happens)
ctrl-a S Split screens
ctrl-a Tab Switch between split screens

So there is a handful, and note that you can cut and paste between screens, which makes it massively useful when on the console.

This concludes this screen article and it will now sit amongst the millions of others on the net. There is a reason why they are all there: screen is the answer.

No comments: