Missing pieces

Everything you should know about technology, but have been missing out

Screen - the terminal window manager

, , ,

Imagine tiling window manager(with only horizontal tiles) and session management like VNC, but for terminal. You'll get program that can manage number of terminal sessions and keeps them running even after you log out. That makes it popular among people who have remote shell account and run IRC client there. Though most people know only about fraction of the useful features it has. It's available for most Unix-like operating systems out there. Some Linux distributions might have installed by default.

You can start it by typing:

screen


By default this displays license and then open shell, but you can define it to start up predefined list of programs. At that point it's hard to tell if Screen is running or not. One way to check it is to try to change window. You can do that by pressing control+a and then 0 (which is number of the first window). If Screen is running, it notifies that window 0 is already open.

You can detach the session by pressing control+a and then ctrl+d. To resume the session, you can type:

screen -r


Though if for some reason Screen is already attached you have to use:

screen -dr


If you want to attach session, without detaching already running session, you can also use:

screen -x


Though keep in mind, screen size is always same in all the attached sessions, so if you want to use whole screen (or shrink to see everything type: control+a and F.

To quit and close all windows, type control+a :quit.

I'll end with summary of commands I use most often (you can always read the manual, if you want to see the full list). Line that starts with screen is command line option. Other commands are typed when screen is runnig.

Attaching and detaching session

Start new session: screen
Attach a session: screen -r
Detach and then attach a session: screen -dr
Share session: screen -x

Working with windows
Create new window: control+a c
Change to window number 1:control+a 1
Change to previously open window: control+a control+a
Go to next window: control+a n
Go to previous window: control+a p

Window tiling
Split window:control+a S
Focus next region:control+a tab
Remove region:control+a X
Remove all regions: control+a Q

Monitoring windows
Monitor for activity: control+a M
Monitor for inactivity: control+a _

Working with multiple sessions
List sessions: screen -ls
Resume session: screen -r session_name
Rename session: control+a :sessionname name
Quitting
quit and close all windows permanently: control+a :quit

Managing windowsTagged: 5 things I'd like to see in Opera

Comments

RamūnasRamunas Sunday, June 10, 2007 1:37:16 PM

screen + irssi = IRC FTW!

Unregistered user Monday, September 10, 2007 12:11:41 PM

toto writes: i know im late question to Window tiling any ideas how i can resize the windows with screen like a small top window displaying some important information and below a bigger one to work with regards, toto

Antero Hytönenanzah Monday, September 10, 2007 6:32:44 PM

Use resize command.

For example if you want to have 10 characters high top window, you could type this after selecting the top window:

ctrl+a :resize 10

If it looks too small you can add one row with following command:

ctrl+a :resize +1

Good question. I use that feature a lot, but didn't remember it when I was writing the article.

Unregistered user Sunday, September 23, 2007 6:56:13 PM

Anonymous writes: How can we disable the resizing behavior of screen? I'm finding this really annoying - I just have to stretch the iTerm window to fit again, but there must be some way to change this in screen.

Antero Hytönenanzah Wednesday, September 26, 2007 8:01:20 PM

Normally Screen should resize itself when terminal is resized. If it doesn't, you can press control+a F

Usually that happens when you have shared session open. Only one session can control the size and other sessions show the screen exactly the same as it's seen in other sessions. It doesn't matter if everything fits in the terminal or not.

So, if you want to keep the size fixed, you can open shared session with screen -x and press control+a F. After that, the shared session is controlling the size and you can resize that terminal to just the right size and go back using the original session.

Unregistered user Saturday, October 13, 2007 7:22:30 AM

Anonymous writes: good

Unregistered user Friday, June 19, 2009 12:49:28 AM

Awesome!!! writes: Great basic tutorial, how do you save "Split setting" after you detach it?

Antero Hytönenanzah Monday, June 22, 2009 11:49:06 AM

You have to edit your .screenrc to save settings: following lines should work, but I haven't tried those out:

#Populate some windows with commands (remember to change prameters to suit your needs)
screen command
title command_title

screen second_command
title second_title

#Do actual splitting
split

focus top
select 0

focus bottom
select 1

mahenmahen21 Monday, July 13, 2009 6:52:57 PM

Wow, that was some awsome tips, thanks.

Write a comment

New comments have been disabled for this post.

June 2012
M T W T F S S
May 2012July 2012
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30