Chris Tankersley

screen - Making Terminals More Efficient

Posted on 2007-06-19

One of the best things about *nix-based systems is the rich command line interface that they all have. No matter what shell you actually use, the entire operating system is at your fingertips with a terminal. The only downside is that multiple windows must be open to do multiple things, right? Not with screen, a basic window manager for terminals. Open multiple sessions and even split-screen to make your life easier. Find out how after the jump.

Screen is easily installed from any package management system. Assuming it isn't installed by default, screen should be in the repository for whatever package management system your OS uses (apt, pkg_add, yum, etc). Once installed, a world of possibilities is open to you.

Starting 'screen'

You can invoke screen from the command line by typing just 'screen' and hitting enter. With this basic command, a new virtual terminal is created inside the terminal that you were just in. This terminal acts just like any other command line in your OS. Still not exciting? Try this:

Start a ping command with 'ping localhost' and let it run. After a few seconds, hit 'CTRL+a then d'. This will drop you back to your original terminal. But what happened to your ping command? It is actually still running in the background. Unlike a regular terminal, screen will continue to run in the background even after you have detached from it (assuming you don't exit fully out). You can rejoin your ping session by invoking screen like this:

screen -d -r

You can see that your ping command is still running! You can now end the ping and fully exit the screen program by typing 'exit'.

Window Management

screen handles more than just one virutal terminal at a time. You can think of each instance of screen as a separate window, and you can have multiple windows open at once. Once you areinside of screen, you can create new windows by typing 'CTRL+a c'. This makes you a new terminal screen and takes you immediately to it. You can cycle through your windows by going to the next window with 'CTRL+a n' or back to the previous window with 'CTRL+a p'

Split Screen

screen also has the functionality of splitting your terminal screen in two. Trying to run a program but want to watch a log file at the same time? Edit and run the program in the top region and watch the log file in the lower. To go split screen, type 'CTRL+a S'. You can move between the screens with 'CTRL+a TAB'. Remember that splitting a screen doesn't automatically create a new window to work in, so after you move into the lower region, create a new screen with 'CTRL+a c'.

Other Common Commands

Here are some other commands that you will find useful while using screen. All of the following commands are preceded by CTRL+a:

Create a new Window:

c

List all Windows:

"

Move to Next Window:

n

Move to Previous Window:

p

Remove current Region:

x

Scroll Mode:

[

Split Display:

S

Switch to Other Region:

TAB


Comments