Note
We are no longer accepting new customers or work orders at this time. Thank you for your interest.
Sometimes you only have text-access to a remote machine, like a Telnet session or SSH connection. Wouldn't it be nice if you could have multiple virtual "windows" within that text window, each with its own shell? While we're dreaming, let's decide that there should be simple keystrokes to jump between windows and create new virtual windows when we need them. And, since everyone hates losing their session when disconnected from the Internet or when rebooting the local computer - let's also require that nothing be lost, we want to "resume" right where we left off - in the middle of editing sessions, commands half-typed, whatever we were doing.
Well guess what?
It's no dream - you can do all this with the screen command!
Most Linux systems have a software package called "screen" already installed. If not, you can usually find an RPM for it at your usual software distro sites. For other operating systems, you can download and build it from source code.
It's free.
Screen's Features
Screen has really awesome features:
How to run Screen
Just type the Unix command:
screen
Your display will clear and you'll get a Unix prompt back. You're now in the "screen" windowing system.
Using Screen
All the commands begin with the CTRL-a character followed by another character.
Create a new window (you start with 1.) | |
Rotate thru the screens | |
Jump to screen #1 (the first one created) | |
Jump to screen #2 (etc.) | |
Power detach (disconnects you from "screen", but leaves the windows running in background) | |
Help |
To delete a window you no longer need, simply "exit" out of it (you may be able to type CTRL-d or whatever your EOF character is.)
To exit out of screen, simply exit all of the windows you've created. But honestly, I don't know why you would do that. A better idea would be to disconnect from the session and log out. All your windows are still running in the background. Now you can log in from anywhere, and resume the screen session! All your windows are back the way you left them, with output and scrollback buffer.
I usually keep my screen sessions going for months - as long as the server stays up.
Disconnecting from Screen
To disconnect your login session from a screen set without killing any processes, type CTRL-A D (or CTRL-A CTRL-D which is easier to type). You'll get sent back to your original login shell; you can now exit.
Resuming Screen
To resume a running screen session, simply type:
screen -r
Remotely Detach Screen
A worst-case scenario though, is if you went home from work, then realized that you left your screens running in a window on your work computer. Now "screen -r" won't work, because the screen is still attached at work.
The solution is to do a remote power-detach - you can force the screen to disconnect from whatever terminal it's hooked to, and just hang out there:
screen -d
Then you can resume the screen connection to interact with it now:
screen -r
Practical Use #1
Suppose you're at work, it's 5:45PM and you want to get out of there, but you have a long running command you need to launch. You can't just run it and log out, it will be killed. You could background it, but then you wouldn't see the output in real-time. You also couldn't interact with it, if it prompts for more information.
So, run the command from within Screen! Now when you go home, you can log back in, resume the screen, and check your command's progress. If it was prompting you for something, you can enter it now to make it continue. You can disconnect the screen again and log off - it has no idea you left.
The next day, you can resume the screen at work and continue working right where you left off.
Practical Use #2
Software development often requires many windows: a few code-editing screens, a man-page lookup screen or 2, maybe a window to check data files or read email, or whatever.
Maybe you're a system administrator and need to have that "root window" open for some special commands or file access. Or different windows logged in to different remote computers, or as different users.
You can run Screen and create windows for each purpose, and switch between them as needed.
Bottom Line
This is all being done with ascii text - the fastest way you can send and receive data is ascii text. If you're an extremely fast typist like I am, or if you're on a slow (modem) connection, you will get the best response time with ascii text sessions like this - much better than any remote-graphical window system including VNC. Screen is powerful yet simple - and the basics are easy to remember.
If you use the shell command-line a lot, give Screen a try. It could really save you some time and frustration.
Here's a Linux Journal article on screen, and an article at Linux Forums which has some instructions on installing it.
Don't miss the latest unix tips and tricks!
Subscribe to our low-volume mailing list:
Privacy Policy
| Copyright © 2006 - 2010 Keith Smith Internet Marketing LLC, all rights reserved. |
| Problem with this web site? please let us know |