Tool of the Day: screen

Only the other day I was talking with someone who does a lot of work on the shell command line, but hadn’t used the GNU screen tool, so I’d better scribble a post about it as I regard it as an absolute must-have for any remote work, for multiple reasons.

First of all, what screen does. You start screen inside a terminal session (local or SSH remote), and then you can create additional sessions though Ctrl-A C. The initial screen is number 0, the next one 1, and so on. You can switch between screens with Ctrl-A # where # is the screen number. This way, you can have multiple things going within a single ssh connection, very handy. But that’s not all!

If you get disconnected (it happens ;-) and you reconnect, your screen sessions will still be there, and running too. You can reattach with screen -r. To do a nice disconnect, you can do Ctrl-A D (detach) before closing your ssh connection.

You can also have multiple screen sessions by name, screens within screens (that confuses me for the control keys so I tend not to use that), and an absolute supertrick is that you can actually share a screen session with someone else. That’s sometimes mighty handy with two engineers to look at something, and also for showing things to clients.

The tool itself is absolutely ancient (aka rock solid, in maintenance mode), I did a quick check and I see references as far back as 1987. I remember using it long long ago, might’ve been a XENIX box. I reckon screen’s authors deserve a prize for creating one of the most useful tools ever!

Default Linux installs often don’t have it, but rectifying that is as simple as sudo apt-get install screen or sudo yum install screen. Then, man screen is your friend, but there are also quite a few decent tutorials on the web.

4 Responses to “Tool of the Day: screen”

  1. You might want to move away from the default binding (CTRL-A), if you like me use a lot CTRL-A to jump at the start of the command line.
    Another good feature of Screen is the scroll back: CTRL-A ESC, then move around with page-up/page-down.
    It’s definitely an important piece in a the sysadmin toolbox, along with a decent shell (hint: zsh).

  2. screen rocks!
    screen has a lot of cool features. I would recommend having a look into setting the hardstatus string. With that its quite comfortable to have an overview over all the windows etc. you are about to use.

    Also splitting CTRL-A S (aka :split) is fun (try it :-). You can log your sessions take screenshots etc. \o/
    One great feature is, you can collaborate with others.
    Via acl-commands other user can attach your screen so you all can work together on a “distant” server with a “distant” colleague.
    In the end I would recommend not to map CTRL-A.
    Working on a lot of different/new servers its easier to get used to it :-)

  3. This is one of my favourite management tools – I’m a big fan. I was using it at my University and work placements at least as far back as 1990.

    One thing you didn’t mention is that there’s a ‘disconnect’ option. This lets you disconnect from a long-running process without killing it, then reconnect later. Very handy for leaving things running when you pop to the Student Union bar for a swift half while running a large compile.

  4. Another package I like (ubuntu server) is screen-profiles.. it seems to be a wrapper around some of the nicer, but more tricky, screen options.

Leave a Comment