Useful Unix Units: Screen (part 1)

Ok children, time to learn about screen, one of the most useful little Unix tools available today.

First, let me get this straight: I don’t believe in the ‘one OS to rule them all’ crap. Horses for courses, and for server work, my horse rides a command line FreeBSD install.

Digression: I’ve never much seen the point of Unix desktops, as they spend most their time trying to do what Windows is made to do. (Hint: If you really want a Unix-based desktop system and still be able to communicate with the rest of the world, start wearing turtlenecks and buy a Mac).

However, for server work, Unix is simple unequalled. You get unparallelled uptime (I was a wizz at getting Win2k uptime[1], but that’s just peanuts to what I get out of FreeBSD without trying. I’ve had servers run unattended with high loads on outdated versions that even the developers considered buggy), great performance on minimal hardware, great server software, and professional-level monitoring, redundancy and security tools.

But of course, running a command line server system limits you to remote shells, and these in turn limit your multi-tasking abilities. At least if you’re on real terminal, you can use Alt-F1 to Alt-F10 to switch consoles, but opening 10 PuTTY instances, while effective, clutters the taskbar.

Screen turns all that upside down. Let’s get it in to your system.

If you’re using BSD unix, as you should be, just type:

# cd /usr/ports/sysutils/screen
# make install clean

If you’re one of those wannabees using Linux instead of Unix, use one of the 42 million ways of installing packages on your unstandardized system. It’ll be there, trust me. Just don’t expect me (or google) to know where. Maybe ask Linus. He’ll probably tell you you should use another distro.

The standard options are fine. Let it rip, and a little while later it’ll tell you it’s finished installing. Now type:

# screen

Now, was that hard?

You’ll get an info screen which will disappear if you click a button (which you’ll do, and regret, cause you realize you have no clue what to do now, and figure that text probably told you exactly that).
So I’ll explain: You are now in a session with a potentional ten virtual consoles. You start with one though. The one you’re now in. If you feel scared, try typing:

# exit

It’ll tell you screen is terminating. It won’t tell you whom it’s terminating, probably John Connor. Short version: You’re safe.

Open screen again (see above), and this time, don’t wimp out. Try doing something. Get a directory listing (I know, CRAZY!). See, just like a normal console. Now hit Ctrl‑A, followed by ‘C’. Where’d your directory listing go? I’ll show you in a minute. First go to another directory, and get another listing.

Done? Now hit Ctrl‑A 0. If you are not getting the first listing, you did something wrong. Go to jail, do not pass start, etc. If you do get the first listing, you have probably figured out that Ctrl‑A 1 will get you the second console (with the second directory listing) again. Good <igh>[2].

Other useful commands:

Command Action
Ctrl‑A C Create a new console. The new console will get the lowest available number (starting at 0).
Ctr‑A 09 Go to console with the specified number, if it exists
Ctrl‑A P/N Go to previous/next console (that is: The one with a number one lower/higher than the current). With wraparound!
exit Typing exit will close the current console. Closing the last console will close screen. You can also do that with Ctrl‑A Ctrl-\, but as I’ll explain next, you probably don’t want to.

That’s the basics. There’s lots more, like copy/pasting between consoles, saving screenshots and whatnot. But on the whole those commands are pretty much all you’ll ever use. If you want more, try typing

# man screen

Now, that makes multitasking a whole lot easier, but it ain’t half of the usefulness of screen. Next time I’ll explain how screen can turn that one little PuTTY session into a roaming, growing and partying affair.

  1. [1]Sadly, Penelope’s latest hardware upgrade also forced an OS upgrade. Luckily, Windows 7 is very strippable.
  2. [2]Insert Gender Here

No Comments

Leave a Reply

Your email is never shared.Required fields are marked *