GNU screen tutorial

February 12, 2009 at 2:35 AM | Posted in Linux | 1 Comment

Screen is best described as a terminal multiplexer utility. It allows you to have multiple virtual terminal instances over a single terminal connection.
Creating a new session
To start screen type screen on command prompt.
$ screen
or you can give screen name also
$screen -S <screen name>
Creating a new window
Type Ctrl+a c.
Every new created screen window is identified by an unique number. The first window (the one you’re actually using) is numbered as 0, while future windows will be labeled as 1, 2, 3 etc.
Switching between windows
a) Use Ctrl-a n and Ctrl-a p to switch to the next or previous window in the list and Ctrl-a space, to toggle through the shells.
b) Use Ctrl-a N, where N is a number from 0 to 9, to switch to the corresponding window.
c) Use Ctrl-a ” to get a full-screen list of windows. You can navigate this list with the arrow keys (or vi-style, with j and k), and pick a window to activate by pressing Enter when it’s highlighted. C-a w will give you a small, non-interactive list of windows.
Renaming Windows
Type Ctrl-a A, it will be prompted for a new window name.
Detaching and reattaching
Type Ctrl-a d for detach
$screen -r to re-attach or resume session

Sharing the session between multiple user
We’ll use a very simple scenario for this one. Let’s say Jake wants to share access to a screen session with Bob. Jake & Bob both have accounts on the system.

1. In order to enable multiuser mode the screen binary must be setuid for root.
# chmod u+s /usr/bin/screen
2. Jake starts a screen session.
jake$ screen -S shared
3. Jake must enable multiuser mode.
CTRL+a : multiuser on
This could be added to ~/.screenrc to have it enabled for all sessions, but case-by-case is probably safer.
4. Jake must add Bob to the access control list for his session.
CTRL+a : acladd bob
5. Bob lists the screen sessions that Jake has available.
bob$ screen -list jake/
There are several screens on:
1951.pts-1.testbox (Private)
1994.shared (Multi, attached)
2 Sockets in /tmp/screens/S-jake.

This shows us that Jake has 2 sessions. The second session named “shared” is a multiuser session & Jake already has it attached.
6. Bob attaches Jake’s multiuser session.
bob$ screen -x jake/shared
Bob could also connect using the PID.
7. Jake can check to see if Bob is connected to his session.
CTRL+a *
This brings up a list of users in a screen session.
term-type size user interface window
———- ——- ———- —————– ———-
xterm 80×24 bob@/dev/pts/11 0(email) rwx
linux 80×24 jake@/dev/tty1 0(email) rwx
[Press Space to refresh; Return to end.]
8. Jake can boot Bob from his screen session.
CTRL+a : acldel bob
Bob is immediately disconnected and sees…
[remote detached]
bob$

Monitoring
Say you’ve got a whole bunch of windows open. One of those windows is idling in a very inactive IRC channel. Since not much goes on in there, you don’t keep that window active but you would like to know when something is said. screen lets you monitor any window for activity by first switching to the window, and then hitting ^A M. When activity in that window occurs, screen will display a message at the bottom.
On the other hand, say one of your windows is a compile of X. There’s lots and lots of activity and you’d like to know when the build is finished. You can monitor for 30 seconds of inactivity by switching to the window and hitting ^A _. When the window goes silent, screen will display a message at the bottom.
These monitoring commands are toggles, so you can turn them off by switching to any monitored window and issuing the command again.

Copy and Paste
Here’s a feature that can be useful if you’re stuck in console mode & don’t have a mouse available. screen has its own built in buffer for copying & pasting text into the same or other windows.
1. Enter copy mode by pressing CTRL+a [
The status bar will read "Copy mode" with column & line information.
2. Move the cursor to the beginning of the block you wish to copy using standard vi keys or the arrow keys.
3.Press the ENTER key.
The status bar will read "First mark set" with column & line information.
4. Move the cursor to the end of the block you wish to copy using standard vi keys or the arrow keys.
5. Press the ENTER key.
The status bar will read "Copied X characters into buffer".
6. Paste the copied text with CTRL+a ]

1 Comment »

RSS feed for comments on this post. TrackBack URI

  1. Nice command and well explained. Will try it out and let you know if face any issue.. :-)


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Blog at WordPress.com. | Theme: Pool by Borja Fernandez.
Entries and comments feeds.

Follow

Get every new post delivered to your Inbox.