Softpanorama
May the source be with you, but remember the KISS principle ;-)

Contents Bulletin Scripting in shell and Perl Network troubleshooting History Humor

GNU Screen -- an Orthodox Window Manager

A "must" tool for Unix Administrators

News Classic Unix Utilities Recommended Links screenrc examples User Manual Reference
Command line options Splitting screen horizontally Detach Splitting screen horizontally Attaching to and detaching from screen sessions  GNU Screen logging
Teraterm The Quick GNU Screen Reference Card bash Tips and Tricks Unix Sysadmin Tips SSH Tips SCP Tips
AWK Tips AWK one liners GNU Screen Tips VIM VIM Tips VNC
OFM Orthodox Editors Admin Horror Stories Tips History of GNU Screen development Etc

Introduction

GNU Screen is a simple, but at the same time very flexible and programmable windows manager. The latest version is 4.2.0. It is often called terminal multiplexer, but the key functionality of screen is in the area of windows management: creation, destruction and resizing of windows. For example it can split the console screen horizontally and display two windows at the same time. Screen is a Unix program (Cygwin version exists and is quite usable). For good Windows terminal emulator see Teraterm.

It can be called one of the most underappreciated Unix utilities, a real jewel of Unix programming art.

In addition to the ability to run many shell processes in a single terminal, screen provides classic windows management capabilities -- the ability to split terminal into regions (horizontal stripes of varying length, each containing its own session.  To explain the value of screen to command line junkies is often difficult but I found that generally the following explanation let them think: often ls on command like is used as "temporary escape from current context" to which you return, often several times. Instead of doing this via ls each time it is much more productive to have two terminal windows open. And generally working with the server using two terminal windows instead of one is a better way to work. Screen provides this capability "out of the box". Moreover if you login to the server via terminal emulator and then close the session you lose all the context of your session and the next time need to start from level zero. If you detach you session from screen you can re-attach to it later saving a lot of keystrokes. If you are over 40 and have problems with carpal tunnel syndrome or other wrists or elbow problems due to overuse/abuse of keyboard, this is (along with programmable keyboard) a life saver. If you are not, why wait :-)

Authodetach capability

Another important (or may be the most important) feature of screen is that like VNC it provides the ability to detach the terminal emulator from the running programs and then reattach the same or new terminal to them.

Autodetach setting might not be enabled by default so it make sense to put a corresponding directive in your .screenrc

autodetach on

This means screen will keep shells and programs running in all windows that you opened even if you accidentally disconnected from the remote server or closed the terminal emulator.

 It is very important is you use connection that is flake. Latly this often happens with secure VPN connections even on very reliable networks. One known "offender" is Optimum Online.

You can start a job at the office and check for it completion at home. Also if you have complex setup you can do it once and reuse during the next connection, saving you time on recreating the environment you need for productive work.

An important feature of screen is that like VNC it provides the ability to detach the terminal emulator from the running programs and then reattach the same or new terminal to them. Then you can reattach to the session using screen -R preserving your environment, history and other session attributes. For sysadmin who administer multiple machines (especially if there multiple cooks in the kitchen) this is a big time saver.

Another important feature that screen it can be used for watching actions of others by connecting to somebody else screen session

screen -x

It also frees administrator from waiting until a particular task ends. He/she can be connected to any number of servers, start a task, detach from the task, and the task keeps running. Then reattach later, check the status and intervene of needed.

Sharing terminal with the other user

Like VNC screen also permits to share a terminal (in read-only mode) with someone else in real time. This permits to collaborate on a project by several remote users located in different places.

Notion of Orthodox interface

Screen has a certain architectural affinity to the orthodox file managers (OFM ), especially deco as well as orthodox editors like vi and THE (the power of command line).  Orthodox system interface has the following properties

Many of programs belonging to this type are descendants of Norton Commander, a file manager first released in 1986 by Norton Computing (since 1990 part of Symantec). But not only file managers can have this type of interface. There is a distinct, but very similar trend in editors  such as vi and THE, windows multiplexers (GNU screen), and minimalist windows managers (ratpoison). We can talk about Orthodox interface as a distinct type of interface different in concepts from traditional GUI interface used in Microsoft Windows and Apple operating systems and simultaneously different (and richer) then plain vanilla  command line interface.  See my article Less is More: A rich functionality behind Spartan interface of Orthodox File Managers  for more information on the topic.

 

Basic usage

We will discuss just for topics that are enough to start productively using screen

 

Screen default prefix

Like in vi in screen you have to hit certain prefix to get to command line. The default prefix is Ctrl-A. For example key combination Ctrl-A C (Press will Ctrl-A, release Ctrl key and press C) opens new window.

This availability of command line operations and related scriptability via .screenrc file makes screen attractive to system administrators who value blend of power and simplicity provided by "orthodox" tools. Like in all orthodox utilities there is an extensive set of commands (mini-language) that can used to modify the behavior of screen.

Ctrl-a is called attention/command key and is similar to Esc in vi (you also can change Ctrl-A to another sequence, if you wish). This sequence presuppose that you are using Sun keyboard (with Ctrl in place of CapsLock) or switched Ctrl and CapsLock keys (in Windows you can use RandyRants SharpKeys -- which provides a nice interface to various registry hacks that remap one key into another, including remapping CapsLock to Ctrl. ).

Remap Ctrl to CapsLock. On Windows that can be done using RandyRants SharpKeys

If the colon (":") is entered after the attention key, then screen switches to command mode and you'll see a highlighted colon prompt at the bottom of the screen. After that, like in vi, you can enter commands that change the behavior of the screen and modify its current configuration. For example you can open and close windows, change size of windows, etc. For example you open new window also by typing command

Ctrl-A: screen

which is equivalent to the shortcut Ctrl-A C that we discussed above.

So shortcut Ctrl-A C and command Ctrl-A: screen are synonyms. This is just an association that is defined in .screenrc file - screen's dotfile. File .screenrc is a list of commands which are executed at startup. While by default screen is using the name .screenrc you can start screen using arbitrary screen's dotfile using option -c, for example

screen -c ~myhome/.screenrc_`uname`

This example demonstrated that you can have multiple .screenrc files and use the one that suits current environment (for example Linux, AIX, Solaris, etc) and the task in hand.

You can also execute predefined sequences of screen commands stored in the files (screen scripts) using the command source. One common application is the execution of the set of command creating a particular combination of windows and loading particular applications into each window. For example, you can load Perl in debugging mode on one window, vi in another and Perl POD browser in the third creating poor man IDE environment. For example

source .screenrc_perl

or

source ~myhome/perl.screenrc

That provides you with the flexibility to have several predefined sets of windows working on a particular task, the capability that improves your productivity dramatically as you can polish the arrangement and gradually connect a set of useful shortcuts as you gain experience with the environment (in the example above, working with Perl). System administrators can (and should) have a custom part of configuration encoded for particular hosts (that's the way I use screen at work) :

source ${HOME}/${HOST}.screenrc

Due to availability of command line interface and scriptability Screen can be considered to be a member of "orthodox" family of utilities which include orthodox file managers (mc, FAR, etc) and orthodox editors (vim, Xedit, THE, etc). Command line can be activated with Ctrl-A: after that you can enter any command from the screen command set to modify behavior of the screen or execute sets of commands (screen script) from particular file using command source.

A typical and probably the simplest application of this capability is to launch a predefined set of windows at screen startup., for example:

source $HOME/.screenrc # read in your normal screenrc
screen top # now start opening windows
screen -t irc epic # with the -t option it's possible to set the window title 
screen -t mail 8 mutt # you can also specify the window number to launch in 
screen -t messages 9 tail -f /var/log/messages

In X-windows world screen inspired several minimalist windows managers which usually are bungled with linux mini-distributions. Classic example of this genre is ratpoison (the name suggest that it is one of the few that not support mouse "out of principle" ;-).

Screen is portable and is an almost a standard utility on all flavors of Unix. It is often preinstalled by default in Linux distributions (for example, Suse 10). And it is easily installed in Solaris, AIX and HP-UX. For example Solaris 10 package can be found on sunfreeware.com:

screen-4.0.2-sol10-intel-local.gz Screen provides an ANSI/vt100 terminal emulator, which can multiplex up to 10 pseudo-terminals - installs in /usr/local. There are further configuration steps in the /usr/local/doc/screen/INSTALL. The etc and terminfo directories containing other relevant files are in /usr/local/doc/screen. The screen package may also require that you install the ncurses package.

Using it, you can run any number of console-based applications -- interactive command shells, curses-based applications, text editors, etc. -- within a single terminal. Many administrators who use screen open a dozen or even more sessions.

Modes of screen usage

Screen can be used in two ways (you can use both local and remote screen instances simultaneously by changing control character in local to say Ctrl-\ via .screenrc, see below):

  1. On local workstation (in this case you multiplex between terminal sessions opened in multiple screen windows). Many administrators use it as a terminal on steroids and have a window for each remote server they administer.
  2. Remotely (in this case you need first to connect to remote machine using, say ssh or telnet, run screen and then multiplex windows on this remote machine). In this case screen provide the ability to have serial local terminal sessions via single ssh or telnet connection (for example one root window and one non-root window).

A nested master-slave invocation of screen is also possible, but it is unclear how practical it is. See Jason White page and my screenrc and my slave screenrc by Tim Chambers. Here is how he explained this method in Slashdot post:

You run an "outer" screen session (the "slave" session) that in turn runs an "inner" (or "master") session. You use the regular escape sequence (Ctrl-A d) to detach from the master, and you map Ctrl-^ to be the control key for the slave session. If you press Ctrl-^ while using screen this way, you'll see one process in the slave session. It's running ssh-agent. That's the key to using ssh with screen. The slave's only purpose is to run ssh-agent. The master runs as a child of that. Consequently, all shells in the master session are running under the ssh-agent. Just run ssh-add from any master shell, and then all shells have your ssh identity.

As we mentioned above, after starting screen you need to open windows using the command Ctrl-a c. Every window in screen is identified by a unique number. The first window is usually numbered 0 (you can change this to one if you do not like counting from zero). For each created windows screen starts default shell. After that user for example can open remote session to a particular server and rename it to simplify recognition after switching to another (an optimal typical number of windows for one screen instance is around a dozen). You can use multiple screen instances each with its own set of servers to connect (DMZ servers, database servers, etc).

Minimal set of commands

Minimal set of commands necessary to use screen productively includes just five commands:

  1. Ctrl-a c to create a new window (Ctrl-a N -- lists the number of the active windows)
  2. Ctrl-a <number> to switch between them (Ctrl-a n, Ctrl-a p or Ctrl-a Ctrl-a will work too providing previous and next windows, but are less convenient and there are two of them instead of one)
  3. Ctrl-a " (windows) Show a list of active 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. As this is one of the most often used commands you will be better off redefining this command as Ctrl-a space (see .screenrc examples on how to do that).

  4. Ctrl-a d. detach from current session. You can also detach just by closing the terminal emulator that contains the session. Neither of these actually end your session. All they do is unbind your session from the current terminal. All of the programs you started running within screen are still running. To reattach type screen -r from the command prompt
  5. Ctrl-a \ (quit) Kill all windows and terminate screen. You can close individual window by exiting shell with command exit.

There are also several more advanced features that can improve your productivity. Among them I would like first of all mention regions.

Regions can dramatically improves your productivity in pure command line environment. This feature turns screen in rudimentary windows manager able to create "strips" non-overlapping horizontal zones each of which corresponds to a separate shell window. To split the screen into two regions just press C-a S. The current window will split into two separate areas with the bottom area blank. To switch to the bottom part press C-a [Tab]. If you need to create a new shell in the new window, so press C-a c. If you want to see one of the existing sessions press Ctrl-a " and select the necessary session. You can create more regions by pressing C-a S again: each time the current "strip" will be split into two. Tabs display the active region shell name in its title bar. You can also switch between tabs being in a region, so e.g.: you have 4 tabs and 2 regions. Each region can display one of these tabs. A nice trick is that upper region can react on the change of the particular environment variable and display either file you are editing or the listing of the current directory. This arrangement is close for the OFM paradigm. You can change the size of each region by entering resize [size], where size is the number of lines.

Detaching and reattaching

You can detach just by closing the terminal emulator that contains the session. Neither of these actually end your session. All they do is unbind your session from the current terminal. All of the programs you started running within screen are still running.

To detach a session, use Ctrl-a d. If that's the only session running (which is typical for novices) you can reattach with Ctrl-a r.

To reattach outside the screen type

screen -r 

You can also use the command:

screen -x

If more than one session is detached, you'll need to provide session PID that you can obtain by listing sessions with the command screen -ls

Summary

List  available screen sessions

screen -ls

Reconnect to specific session

screen -D -R main

Connect to specific session in "watching/spy mode"

screen -x screen_session_name

If there is a single session only screen -x will suffice.

Reattaching to session within the screen

If you have more than one session running, you will need to know the PID to attach or reattach to an existing session. To detach a session, use Ctrl-a d. If that's the only session running, you can reattach with Ctrl-a r If more than one session is detached, you'll need to run Ctrl-a r XXXXX where XXXXX is the PID.

More advanced usage

We will cover the following topics here

 

Splitting the screen in two horizontal panes

The key additional feature of Screen that you need to master after mastering basic commands and detach/reattach operation is split command.

Ctrl-a S (split, capital s, please!). Screen can horizontally by split into regions(panels), each holding a different terminal. After you split the window you need to move to the new region using Ctrl-a Tab (Press Ctrl-A release control key and only then press Tab key) and create a session in it using Ctrl-a-c.

Level 1 command set

Here is slightly more elaborate set of commands, which we will call Level 1 command set. It includes regions-related commands:

  1. Ctrl-a d. detach from current session.

  2. Ctrl-a A (title) Allow the user to enter a name for the current window (useful fo naming each window according to the purpose (for example each can represent a different directory).

  3. Swiching windows
  4. Ctrl-a S (split, capital s, please!). Screen can horizontally by split into regions(panels), each holding a different terminal. After you split the window you need to move to the new region using Ctrl-a Tab (Press Ctrl-A release control key and only then press Tab key) and create a session in it using Ctrl-a-c.

  5. Ctrl-a <Tab> (focus) move the the next split window
  6. Ctrl-a X (remove) Close current region
  7. Ctrl-a w lists windows in one like with the active marked by asterism. This is a noninteractive list and you cannot navigate it. Interactive list is by default assigned to Ctrl-a "
  8. Screen remembers a configurable number of scrollback lines. You can access the scrollback buffer by entering "copy mode", which is accomplished by typing Ctrl-a [. You can mark text anywhere in the scrollback buffer and paste it with Ctrl-a ]. Screen is also capable of logging to files.
  9. Screen has features that allow you to monitor a window for silence, useful, for example, for knowing when a compile has finished. To start or stop monitoring the current window for 30 seconds of silence, type Ctrl-a _; to start or stop monitoring a window for activity, type Ctrl-a M.
  10. To close sessions you need to to close each of your screen windows. Exit whatever programs or shells each is running, and they will go away. When the last program running inside screen is exited, screen itself will go away. You can forcefully quit screen with Ctrl-a Ctrl-\.

Extended list of screen commands

As you progress you "screen vocabulary" extends and in some point you can switch from Level 1 command set to Level 2 command set which includes several additional useful commands (and first of all bindkey command):

Ctrl-a ' (select)
Prompt for a window name or number to switch to.
Ctrl-a " (windowlist -b)
Present a list of all windows for selection.
Ctrl-a 0 (select 0)
... ...
Ctrl-a 9 (select 9)
Ctrl-a - (select -)
Switch to window number 0 - 9, or to the blank window.
Ctrl-a tab (focus)
Switch the input focus to the next region.
Ctrl-a Ctrl-a (other)
Toggle to the window displayed previously.
Note that this binding defaults to the command character typed twice, unless overridden. For instance, if you use the option "-e]x", this command becomes "]]".
Ctrl-a a (meta)
Send the command character (Ctrl-a) to window. See escape command.
Ctrl-a A (title)
Allow the user to enter a name for the current window (useful fo naming each window according to the purpose (for example each can represent a different directory).
Ctrl-a b
Ctrl-a Ctrl-b (break)
Send a break to window.
Ctrl-a B (pow_break)
Reopen the terminal line and send a break.
Ctrl-a c
Ctrl-a Ctrl-c (screen)
Create a new window with a shell and switch to that window.
Ctrl-a C (clear)
Clear the screen.
Ctrl-a d
Ctrl-a Ctrl-d (detach)
Detach screen from this terminal.
Ctrl-a D D (pow_detach)
Detach and logout.
Ctrl-a f
Ctrl-a Ctrl-f (flow)
Toggle flow on, off or auto.
Ctrl-a F (fit)
Resize the window to the current region size.
Ctrl-a Ctrl-g (vbell)
Toggles screen's visual bell mode.
Ctrl-a h (hardcopy)
Write a hardcopy of the current window to the file "hardcopy.n".
Ctrl-a H (log)
Begins/ends logging of the current window to the file "screenlog.n".
Ctrl-a i
Ctrl-a Ctrl-i (info)
Show info about this window.
Ctrl-a k
Ctrl-a Ctrl-k (kill)
Destroy current window.
Ctrl-a l
Ctrl-a Ctrl-l (redisplay)
Fully refresh current window.
Ctrl-a L (login)
Toggle this windows login slot. Available only if screen is configured to update the utmp database.
Ctrl-a m
Ctrl-a Ctrl-m (lastmsg)
Repeat the last message displayed in the message line.
Ctrl-a M (monitor)
Toggles monitoring of the current window.
Ctrl-a space
Ctrl-a n
Ctrl-a Ctrl-n (next)
Switch to the next window.
Ctrl-a N (number)
Show the number (and title) of the current window.
Ctrl-a backspace
Ctrl-a h
Ctrl-a p
Ctrl-a Ctrl-p (prev)
Switch to the previous window (opposite of Ctrl-a n).
Ctrl-a q
Ctrl-a Ctrl-q (xon)
Send a control-q to the current window.
Ctrl-a Q (only)
Delete all regions but the current one.
Ctrl-a r
Ctrl-a Ctrl-r (wrap)
Toggle the current window's line-wrap setting (turn the current window's automatic margins on and off).
Ctrl-a s
Ctrl-a Ctrl-s (xoff)
Send a control-s to the current window.
Ctrl-a S (split)
Split the current region into two new ones.
Ctrl-a t
Ctrl-a Ctrl-t (time)
Show system information.
Ctrl-a v (version)
Display the version and compilation date.
Ctrl-a Ctrl-v (digraph)
Enter digraph.
Ctrl-a w
Ctrl-a Ctrl-w (windows)
Show a list of window.
Ctrl-a W (width)
Toggle 80/132 columns.
Ctrl-a x
Ctrl-a Ctrl-x (lockscreen)
Lock this terminal.
Ctrl-a X (remove)
Kill the current region.
Ctrl-a z
Ctrl-a Ctrl-z (suspend)
Suspend screen. Your system must support BSD-style job-control.
Ctrl-a Z (reset)
Reset the virtual terminal to its "power-on" values.
Ctrl-a . (dumptermcap)
Write out a ".termcap" file.
Ctrl-a ? (help)
Show key bindings.
Ctrl-a Ctrl-\ (quit)
Kill all windows and terminate
screen.
Ctrl-a : (colon)
Enter command line mode.
Ctrl-a [
Ctrl-a Ctrl-[
Ctrl-a esc (copy)
Enter copy/scrollback mode.
Ctrl-a ] (paste .)
Write the contents of the paste buffer to the stdin queue of the current window.
Ctrl-a {
Ctrl-a } (history)
Copy and paste a previous (command) line.
Ctrl-a > (writebuf)
Write paste buffer to a file.
Ctrl-a < (readbuf)
Reads the screen-exchange file into the paste buffer.
Ctrl-a = (removebuf)
Removes the file used by Ctrl-a < and Ctrl-a >.
Ctrl-a , (license)
Shows where screen comes from, where it went to and why you can use it.
Ctrl-a _ (silence)
Start/stop monitoring the current window for inactivity.
Ctrl-a * (displays)
Show a listing of all currently attached displays.

Here are some examples of keyboard bindings:

bindkey -d # Show all of the default key bindings. The application mode entries are marked 
	with [A]. 
bindkey -k k1 select 1 # Makes the "F1" key switch to window one. 
bindkey -k F1 command # Makes the F11 (not F1!) key an alternative screen escape (besides `Ctrl-a'). 

Changing attention key sequence (Ctrl-A)

You can also easily change Ctrl-A (the default attention/command key sequence) to another sequence. This can be done either via putting command escape into .screenrc or via a switch when you start screen.

  1. -e xy specifies the command character to be x and the character generating a literal command character to y (when typed after the command character). The default is «Ctrl-a» and `a', which can be specified as "-e ^Aa". When creating a screen session, this option sets the default command character. In a multi-user session all users added will start off with this command character. But when attaching to an already running session, this option changes only the command character of the attaching user. This option is equivalent to either the commands «defescape» or «escape» respectively.

    If you invoked screen by using "screen -e ^Ww" you can see that ^W became attention/command key combination. So ^W-? gets the Help screen. Ctrl-A and then ? no longer worked.

  2. Adding co the .screenrc file using escape command is explained in the man page:

    escape xy

    Set the command character to x and the character generating a literal command character (by triggering the "meta" command) to y (similar to the -e option). Each argument is either a single character, a two-character sequence of the form "^x" (meaning "Ctrl-x"), a backslash followed by an octal number (specifying the ASCII code of the character), or a backslash followed by a second character, such as "\^" or "\\". The default is "^Aa".

    For example if you add

    escape ^\\ 

    into the .screenrc you will see that ^\ became attention key sequence instead of default ^A.

User friendly status line

It is also important to make screen more user friendly. In order better see what open windows you have you can do it by adding the following lines to .screenrc :

	1 hardstatus alwayslastline
	2 hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{=
kw}%?%-Lw%?%{r}(%{W}%n*%f %t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B}
%Y-%m-%d %{W}%c %{g}]'

In his paper Screen Tips & Tricks Łukasz Olender suggests several other variants:

But so as not to get lost in these windows, I suggest you create tabs similar to those found in web browsers. You can do this by writing to your configuration file ~/.screenrc one of the following codes:

hardstatus alwayslastline
hardstatus string '%{= mK}%-Lw%{= KW}%50>%n%f* %t%{= mK}
%+Lw%< %{= kG}%-=%D %d %M %Y %c:%s%{-}'

or

hardstatus alwayslastline
hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{= kw}%?%-Lw%?%{r}
(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B} %d/%m
%{W}%c %{g}]'

or

hardstatus alwayslastline
hardstatus string '%{gk}[ %{G}%H %{g}][%= %{wk}%?%-Lw%?%{=b kR}
(%{W}%n*%f %t%?(%u)%?%{=b kR})%{= kw}%?%+Lw%?%?%= %{g}][%{Y}%l%{g}]
%{=b C}[ %m/%d %c ]%{W}'

With the first code each tab will have a number, a name plus time and date. The second one will give you tabs that will be created in the center and the active tab will be highlighted in red and also have the hostname displayed. The last code will additionally display the processor usage. You can create your own codes but it is a rather specialized task - I refer you to the system manuals for more information.

You can combine ideas from those into you own status line that suits your need. But in any case it is important to improve visibility of windows by using this capability of screen.

RC file

Dr. Nikolai Bezroukov


Top updates

Bulletin Latest Past week Past month
Google Search


NEWS CONTENTS

Old News ;-)

 2011-2020  2001-2010

[Nov 25, 2014] GNU screen [quick_reference]

Useful reference. Prints nicely on two pages.

Getting in

start a new screen session with session name screen -S <name>
list running sessions/screens screen -ls
attach to a running session screen -x
… to session with name screen -r <name>
the “ultimate attach” screen -dRR (Attaches to a screen session. If the session is attached elsewhere, detaches that other display. If no session exists, creates one. If multiple sessions exist, uses the first one.)
detach a running session screen -d <name>

Escape key

All screen commands are prefixed by an escape key, by default C-a (that's Control-a, sometimes written ^a). To send a literal C-a to the programs in screen, use C-a a. This is useful when when working with screen within screen. For example C-a a n will move screen to a new window on the screen within screen.

Getting out

detach C-a d
detach and logout (quick exit) C-a D D
exit screen C-a \ Exit all of the programs in screen.
force-exit screen C-a C-\ (not recommended)

Help

See help C-a ? (lists keybindings)

The man page is the complete reference, but it's very long.

Window Management

create new window C-a c
change to last-visited active window C-a C-a (commonly used to flip-flop between two windows)
change to window by number C-a <number> (only for windows 0 to 9)
change to window by number or name C-a ' <number or title>
change to next window in list C-a n or C-a <space>
change to previous window in list C-a p or C-a <backspace>
see window list C-a " (allows you to select a window to change to)
show window bar C-a w (if you don't have window bar)
close current window Close all applications in the current window (including shell)
kill current window C-a k (not recommended)
kill all windows C-a \ (not recommended)
rename current window C-a A

Split screen

split display horizontally C-a S
split display vertically C-a | or C-a V (for the vanilla vertical screen patch)
jump to next display region C-a tab
remove current region C-a X
remove all regions but the current one C-a Q

Scripting

send a command to a named session screen -S <name> -X <command>
create a new window and run ping example.com screen -S <name> -X screen ping example.com
stuff characters into the input buffer
using bash to expand a newline character
(from here)
screen -S <name> [-p <page>] -X stuff $'quit\r'
a full example
# run bash within screen
screen -AmdS bash_shell bash
# run top within that bash session
screen -S bash_shell -p 0 -X stuff $'top\r'
 
# ... some time later
 
# stuff 'q' to tell top to quit
screen -S bash_shell -X stuff 'q'
# stuff 'exit\n' to exit bash session
screen -S bash_shell -X stuff $'exit\r'

Misc

redraw window C-a C-l
enter copy mode C-a [ or C-a <esc> (also used for viewing scrollback buffer)
paste C-a ]
monitor window for activity C-a M
monitor window for silence C-a _
enter digraph (for producing non-ASCII characters) C-a C-v
lock (password protect) display C-a x
enter screen command C-a :
enable logging in the screen session C-a H

Version 4.2.1 released

GNU Screen v.4.2.0

Vertical split is now  provided.

After six years since the last release and 27 years of existence of the project, a new release of GNU screen was presented by Amadeusz Sławiński, the new maintainer of the project, who was selected at the beginning of April.

He was previously was responsible for the support of a branch of screen on GitHub, which, compared to the official line contained 300 patches and enhancements.

Now all these changes are transferred back to to the main project and will be available in screen 5.

Release 4.2 was chosen as the 4.1 branch has already been created at the time of the merger. By its composition, the branch 4.2 similar 4.1. Packages with a new release is already available for users of Arch Linux and Debian Unstable (coming soon in Debian Testing).

the new version introduces support for layouts, added Association of funts installed the Windows, improved mouse support. Vertical split is now also provided. It also supports 256-color terminal, the ability to have multiple stories input, auto-completion of commands by pressing the tab key, initial support connection scripts-handlers, new commands (layout, group, unbindall, rendition, mousetrack).

As some of the changes affect compatibility with previous version (for example interaction with the back-end process rather than named pipes now uses sockets), soall sessions should be closed before performing the update.

Version 5, which is in words will contain substantial clean up of the code base. Some innovations developed  prepared outside the official branch might be included too, such as 256-color status bar, support of full-color palettes, and placement of banner at the top line and the possibility of moving status bar in the upper part.


From: Amadeusz Sławiński
Subject: [screen-devel] GNU Screen v.4.2.0
Date: Thu, 17 Apr 2014 00:53:22 +0200
Hello everyone,

it is my pleasure to announce release of GNU Screen v.4.2.0

available at http://download.savannah.gnu.org/releases/screen/
(I will also upload to ftp.gnu.org as soon as my access is authorized)

Many are probably using it due to their distributions packaging
development versions, so they know at least some of changes.
Short list of them:
 * layouts
 * window groups
 * better mouse support
 * vertical split
 * new and expanded commands

For full list of changes please check Changelog.


Please note that due to some changes it may be not possible to attach
to sessions created with older binaries.


With this I also plan to put v.4 into maintenance mode and start
developing v.5 with cleaned up source code, new features (some already
in development tree, currently outside of official repository):
 * 256 color hardstatus
 * truecolor
 * firstline hardstatus
 * top line caption
 and more

Amadeusz Slawinski

Re: [screen-devel] GNU Screen v.4.2.0


From: Axel Beckert
Subject: Re: [screen-devel] GNU Screen v.4.2.0
Date: Thu, 17 Apr 2014 09:10:41 +0200
User-agent: Mutt/1.5.20 (2009-06-14)

Hi Amadeusz,

On Thu, Apr 17, 2014 at 12:53:22AM +0200, Amadeusz Sławiński wrote:
> it is my pleasure to announce release of GNU Screen v.4.2.0

Not a bad idea to _not_ call this 4.1.0 -- a version number floating
around with -dev suffixes in quite many distros. :-)

Good to see that you got commit access, etc.

> Please note that due to some changes it may be not possible to attach
> to sessions created with older binaries.

There's a patch for that at
http://patch-tracker.debian.org/patch/series/view/screen/4.1.0~20120320gitdb59704-9/60-644788-screen-4.1.0-4.0.3-interoperability.patch

Feel free to include it in 4.2.1. (Not tried if it still applies, but
I will try soon. :-)

P.S.: I recently got one report that someone uses Screen's Zmodem
support for some embedded board (Soekris) maintenance. No further
details though as I didn't get that first hand.

                Kind regards, Axel

Re: [screen-devel] GNU Screen v.4.2.0


From: Jürgen Weigert
Subject: Re: [screen-devel] GNU Screen v.4.2.0
Date: Thu, 17 Apr 2014 15:44:05 +0200

config.h.in is generated when you run autogen.sh
 
Several other autogenerated files are also no longer included. Which is a good thing for maintenance, as they can no longer go out of sync.

 
I patched the specfile to run autogen.sh and make depend. The later is a horrible hack. It patches the Makefile, and would fail if the osdef.h and comm.h are not yet generated.
 


 
On Thu, Apr 17, 2014 at 2:22 PM, Jeroen Roovers <address@hidden> wrote:
 
On Thu, 17 Apr 2014 00:53:22 +0200
Amadeusz Sławiński <address@hidden> wrote:

> it is my pleasure to announce release of GNU Screen v.4.2.0

 
Very nice.
 

> available at http://download.savannah.gnu.org/releases/screen/
> (I will also upload to ftp.gnu.org as soon as my access is authorized)

 
config.h.in is missing from the tarball.

Re: [screen-devel] GNU Screen v.4.2.0


From: Jürgen Weigert
Subject: Re: [screen-devel] GNU Screen v.4.2.0
Date: Thu, 17 Apr 2014 15:52:37 +0200

Amadeusz et all:
 
At opensuse, we have a wagonload of patches, that I'd like to offer for your review and merge into upstream.
See attached.

  * added msg_version_3.patch (ouch, incompatible protocol, to be upstreamed asap)
  * keep screen-man-loginshell.diff (to be upstreamed)
  * keep term_too_long.diff (savannah#30880, to be upstreamed)
  * keep use_locale.diff (from address@hidden 2012, check?)
  * keep screen-4.0.3-ipv6.patch (builtin telnet, to be upstreamed)
  * keep screen_enhance_windows_list.patch (to be upstreamed)
  * keep screen-poll-zombies.patch (to be upstreamed)
  * keep xX_string_escape.patch (renamed from show_all_active.patch, to be upstreamed)
  * keep sort_command.patch (from trenn 2011, to be upstreamed)
  * keep libtinfo.diff (from coolo 2011, why exactly?)
  * keep global_screenrc.patch (renamed from screen-4.0.2.dif)


 
CCed Thomas, Michael: submit requests 230477 and 230482
 
 sent to Factory and 13.1:Update
 

Re: [screen-devel] GNU Screen v.4.2.0


From: Amadeusz Sławiński
Subject: Re: [screen-devel] GNU Screen v.4.2.0
Date: Fri, 18 Apr 2014 18:54:03 +0200

On Thu, 17 Apr 2014 15:52:37 +0200
Jürgen Weigert <address@hidden> wrote:

> Amadeusz et all:
> At opensuse, we have a wagonload of patches, that I'd like to offer
> for your review and merge into upstream.

If anyone else has any patches, please share ;)

>
> * added msg_version_3.patch (ouch, incompatible protocol, to be
> upstreamed asap)

on screen-v4 branch

> * keep screen-man-loginshell.diff (to be upstreamed)
> * keep term_too_long.diff (savannah#30880, to be upstreamed)

I used a bit different version based on what I found in manpages
http://git.savannah.gnu.org/cgit/screen.git/commit/?h=screen-v4&id=44020241d033555e8e90fad3c88617dce1aed0bb

> * keep use_locale.diff (from address@hidden 2012, check?)
> * keep screen-4.0.3-ipv6.patch (builtin telnet, to be upstreamed)
> * keep screen_enhance_windows_list.patch (to be upstreamed)
> * keep screen-poll-zombies.patch (to be upstreamed)
> * keep xX_string_escape.patch (renamed from show_all_active.patch,
> to be upstreamed)
> * keep sort_command.patch (from trenn 2011, to be upstreamed)
> * keep libtinfo.diff (from coolo 2011, why exactly?)

For this I used patch from gentoo, as it seems to provide better
checks, it checks for alternative libraries to use instead of curses one

> * keep global_screenrc.patch (renamed from screen-4.0.2.dif)

With regards to rest of the patches, I would like to merge them when I
start merging my tree (some of them are already in there).

Amadeusz

Re: [screen-devel] GNU Screen v.4.2.0


From: Axel Beckert
Subject: Re: [screen-devel] GNU Screen v.4.2.0
Date: Fri, 18 Apr 2014 22:38:54 +0200
User-agent: Mutt/1.5.20 (2009-06-14)

Hi,

On Fri, Apr 18, 2014 at 06:54:03PM +0200, Amadeusz Sławiński wrote:
> On Thu, 17 Apr 2014 15:52:37 +0200
> > At opensuse, we have a wagonload of patches, that I'd like to offer
> > for your review and merge into upstream.

Same counts for Debian as mentioned before. :-)

> If anyone else has any patches, please share ;)

The patches I used against 4.2.0 for the Debian package (available in
Debian Experimental for now) should be available for easy reviewing at
http://patch-tracker.debian.org/package/screen/4.2.0-1 but Debian's
patch tracker seems down for the moment. :-(

A less comfortable variant is at
http://anonscm.debian.org/gitweb/?p=collab-maint/screen.git;a=tree;f=debian/patches

Most of the patches should be suitable for upstream inclusion.

Solely those which change the size of some string lengths (user name,
$TERM, etc.) may cause issues as they may change the internal protocol
between client and server processs as far as I understood it.

The patch 80EXP_session_creation_time.patch should be regarded as
feature as it changes default behaviour. It sorts "screen -ls" output
by creation time and also affects "screen -rr" and friends -- IIRC it
makes them more deterministic. Maybe something for the development
branch and the 5.x releases.

                Kind regards, Axel

Re: [screen-devel] GNU Screen v.4.2.0


From: Amadeusz Sławiński
Subject: Re: [screen-devel] GNU Screen v.4.2.0
Date: Fri, 25 Apr 2014 15:09:30 +0200

> A less comfortable variant is at
> http://anonscm.debian.org/gitweb/?p=collab-maint/screen.git;a=tree;f=debian/patches
> 
> Most of the patches should be suitable for upstream inclusion.
> 
> Solely those which change the size of some string lengths (user name,
> $TERM, etc.) may cause issues as they may change the internal protocol
> between client and server processs as far as I understood it.
> 
> The patch 80EXP_session_creation_time.patch should be regarded as
> feature as it changes default behaviour. It sorts "screen -ls" output
> by creation time and also affects "screen -rr" and friends -- IIRC it
> makes them more deterministic. Maybe something for the development
> branch and the 5.x releases.
> 
>               Kind regards, Axel

Hey,

I've went through debian patches and I've applied most of them.
Here are the ones I've not applied with comments.

11replace_doc_paths.patch - seems debian specific

13split_info_files.patch - also debian specific?

26source_encoding.patch - cosmetic change for source code

45suppress_remap.patch - I've checked the logs and it seems like there
was already a revert of revert... are you sure it doesn't break
anything?

47screen-cc.patch - I will first check patches from Fedora, instead of
monolithic one ;)

48screen-ipv6.patch - it's a feature -> v5

49long-usernames.patch - already fixed

50increase-max-TERM-length.patch - already fixed

58-show-encoding-hardstatus.patch - feature -> v5

60-644788-screen-4.1.0-4.0.3-interoperability.patch - still not sure
about this one

80EXP_session_creation_time.patch - not applied -> v5

Amadeusz

[Jan 23, 2012] A guide to GNU Screen by Steve ‘Ashcrow’ Milner and Anderson Silva

October 5, 2007 Red Hat Magazine

Sharing a session with others

Another great application of Screen is to allow other people to login to your station and to watch the work you are doing. It is a great way to teach someone how to do things on the shell.

Setup to allow screen to be shared

  1. As root: chmod u+s /usr/bin/screen (Screen has to be SUID if you want to share a term between two users.)
    Note: SUID allows an executable to be run by the owner of that file, instead of with the user's own permission. There are some security concerns when doing this, so use this tip at your own discretion.
  2. chmod 755 /var/run/screen
  3. Log out of root, and run Screen as the user who is going to share the session:
    screen
  4. Press Ctrl+a, then type :multiuser on and press Enter.
  5. Press Ctrl+a, then type :acladd steve (”steve” is the username of the person who will connect to your screen session).

Connecting to the shared screen:

  1. SSH into the workstation that you are going to watch the screen session on.
  2. On your terminal type: screen -x anderson/ (”anderson” is the username of the person who is sharing the screen session. You need the / at the end.).

And now both users (from the host and guest) will be sharing a screen session and can run commands on the terminal.

Working from multiple locations

Let's say you have a screen session open at work with X number of windows on it. Within those screens you may be running an IRC client, an SSH connection to the web server, and your favorite text-based email client. It's 5 p.m. and you have to go home, but you still have work left to do.

Without Screen you would probably go home, VPN into your company's network, and fire up all the shells you need to keep working from home. With Screen, life gets a little easier.

You can simply SSH into your workstation at work and list your available screen sessions with the command:

screen -ls

And connect to the sessions you were running at work with the command:

screen -x screen_session_name

This way screen will let you pick things up exactly from where you left off.

Applications to make Screen your window manager

Now that you have seen what Screen can do for you, you probably are wondering how to make it your main interaction point, like a terminal window manager.

Let's start with IRC, a very common and popular chat system. Instead of using a graphical client like Pidgin, install Irssi. Irssi sports a slick console interface, tons of add-ons and scripts, and can be enhanced with Perl. It's even theme-able!

Another important part of any user's setup is email. Today most people use graphical clients such as Thunderbird, Evolution, or Sylpheed. My favorite client happens to run in a terminal: Mutt. While Mutt isn't the easiest client in the world to set up, it sure is a joy to use. You can even use your favorite console text editor for doing emails.

Speaking of favorite text editors, there is a good chance that you work on some code projects or configurations. Instead of using gedit/kedit or powering up a heavy IDE such as Eclipse, you can pick up on Vim. Vim is a powerful text editor which, as is stated on the Vim website, could be considered an entire IDE in itself and sports syntax coloring in over 200 programming languages. If Vim doesn't fit your style, there is always emacs, nano, or JOE.

Now all you need you need to do is edit your ~/.screenrc to meet your needs.

My ~/.screenrc looks like the following:

	1 hardstatus alwayslastline
	2 hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{=
kw}%?%-Lw%?%{r}(%{W}%n*%f %t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B}
%Y-%m-%d %{W}%c %{g}]‘
	3
	4 # Default screens
	5 screen -t shell1	0
	6 screen -t shell2	1
	7 screen -t server	2 	sh me@myserver
	8 screen -t IRC	7	irssi
	9 screen -t Mail	8	mutt

Once you get used to the shortcuts in GNU screen, not only will your desktop become more organized (due to the lower number of open windows), but your efficiency as a developer or system administrator will increase not only at work but at your home office as well.

Richard :

Just like abeowitz, I’m wondering whether it is possible to use screen to send commands to multiple screens.

According the documentation this should be possible with the “at” command, but I don’t get it to work.

So the command sequence:
C-a :at # date
Should result in a date executed on all windows (to my understanding, but the result I get is:
“: at: at least two arguments required”)

OTOH according the TODO file at:
ftp://ftp.uni-erlangen.de/pub/utilities/screen/screen-4.0.3.tar.gz
states: “- type into several windows at once (for cluster admins)”
That file has been changed in august 2003 for the last time…

Hopefully someone reading this article knows how to use the at command???

Hey Richard!:

With the ‘at’ command, you can send commands to other windows that have to be typed when you press C-a :
This changes the title of a window in a certain screen session:
screen -X at 1 title blublublu

Richard:

A way to broadcast commands to all windows is the following:
^a:at \# stuff “ls12?

Thanks goes to Michael, (one of the screen devs) who provided this information to me.The command above should read: double quote ls backslash zero twelve double quote. Somehow the parser removes the blackslash zero. One more try:
^a:at \# stuff “ls\\12″

Rob Nichols:

This is a great intro. I’ve used screen for many years. (Just stopped to count. I think it’s been a decade!) However, I’d never bothered with learning about the hardstatus line until this article. It’s a nice addition. Thanks!

P.S. I think there are two mistakes in the example given. Again, this is my first foray in screen’s string escapes, so I might be way off. I think “%{=kw}” should have a space, as “%{= kw}”. Without this change on my system windows before the current are green instead of white. I also think there is an extra “%?” before the the closing “]” on the window list. This made no difference on my system. Here’s a version with these changes.

hardstatus string ‘%{= kG}[ %{G}%H %{g}][%= %{= kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%= %{g}][%{B}%Y-%m-%d %{W}%c %{g}]‘

John:

I’ve used Screen for more than a decade. For years now I’ve used it to keep open ssh sessions to various systems, doing things like tailing logs and such, and disconnecting then reconnecting when necessary. My latest session has been running upwards of 2 years, only ever bringing it down for critical patching. Sometimes I connect to the same session from multiple windows, displaying different screen “windows” for multiple views. I also use an always on statis as well.

The few modifications I’ve made are to increase the MAXWIN param to allow for more windows, and change the command key to ^w so I don’t have to unlearn my emacs ^a habits.

John Pye:

One good use of Screen is when performing remote updates of systems using apt-get or yum. You can start the update going, then disconnect, then come back later and check that it finished OK. If your remote connection goes down, it doesn’t mess everything up. Also, using the screen ‘logging’ function, you can keep a full history of the update, and check it for error messages that you might have missed.

[Jan 23, 2012] Using GNU Screen

Here's a list of all the commands we've covered:

[Feb 12, 2004] Curiosity is bliss Essential utility screen

Screen is a command line utility that comes with lots of Unix variants (including Linux). It is a bit hard to describe and to discover. It provides two main features: multiplexing a terminal and detaching/re-attaching sessions.

I originally got shown this by my "System programming" TA, when I asked him if I could disconnect X11 application from one terminal and have them re-open (in the same state) onto another terminal. It turns out this is possible for X11 applications (see xmove or xmx, proxy-based redirections, or guiEvict <via sweetcode>, described in this paper). But "screen" although limited to text applications is so useful that I dropped my search for its X11 equivalent.

Multiplexing: If you start a remote shell (say SSH) but want to do more than one thing at a time, you may want to open more sessions, but you can also use screen. It allows you to switch between multiple shells on the same connection.
You need to first run "screen", then use "Ctrl-A Ctrl-C" (control A, control C) to create a new shell, and you now can switch between shells with "Ctrl-A Ctrl-*" where * is the number for you shell (for ex, use "Ctrl-A Ctrl-1" to switch to shell 1).

Session migration: Let's say you need to disconnect from that session, but you want to continue it from another computer. You can use "Ctrl-A Ctrl-D" to detach screen. All the shells will be maintained, and you can reconnect to the remote machine again and type "screen -R" to re-attach to the original session. This is also very useful in can the connection is lost by accident.

macosxhints.com - Use 'screen' as a serial terminal emulator

I often have to do router configuration via a console port, so I use a Keyspan Serial Adapter to get access. Two problems then present themselves:
  1. ZTerm is a horrible Mac OS X app. It hasn't been updated in five years or so, and isn't a Universal Binary. The developer doesn't seem in any hurry to rectify the situation. It is not worth the shareware fee in its current form.
  2. Minicom requires installation of Fink or MacPorts and is overly complex.
Solution: Use screen, Terminal, and a little AppleScripting.

First, launch Script Editor and type/paste in the following code:

tell application "Terminal"
  do script with command "screen /dev/tty.KeySerial1"
  set number of rows of window 1 to 100
  set number of columns of window 1 to 80
  set background color of window 1 to "black"
  set normal text color of window 1 to "green"
  set custom title of window 1 to "SerialOut"
end tell
Compile and save as an app from within Script Editor, and you have a double-clickable application to launch a serial Terminal session. You may want to customize this slightly -- you can change the screen colors or number of columns or rows. You may also need to customize the screen command with a different device name if you are using something other than the Keyspan Serial Adapter (do an ls tty* of the /dev/ directory to get the right name).

screen uses Control-A to take commands directed to it. So type Control-A followed by Control-\ to exit your screen session. If you fail to do this and exit a Terminal session, you'll leave the screen session alive and the serial resource unavailable until you kill the screen session manually. man screen will show you further commands to send to a screen session.

If anyone can reply with a link to a tutorial on how to wrap an interactive Unix App in Cocoa, that would be the next step -- it would be nice to do this without involving Terminal. If you prefer to use Minicom, you could still use the AppleScript to wrap it into a nice launchable app -- use this older hint to find the right command line commands.

Continued...

Recommended Links

Softpanorama Top Visited

Softpanorama Recommended

Solaris Packages

Solaris Package Archive -- GNU screen 3.9.4

GNU screen 3.9.4 provides you with an ANSI/vt100 terminal emulator, which can multiplex up to 10 pseudo-terminals. On startup, it executes $SHELL in window 0. Then it reads $HOME/.screenrc to learn configuration, keybindings, and possibly open more windows. GNU screen has the ability to detach from your virtual screens and re-attach at a later time.

Email To
Send bug reports or queries to screen@uni-erlangen.de.

Upgrading Packages
When upgrading from an earlier GNU screen package, remember to pkgrm GNUscreen before you pkgadd the new version.

Solaris Issues
Click here to read about 32 bit and 64 bit packages.

Source Code
You can ftp the source code from ftp://ftp.gnu.org/pub/gnu/screen/screen-3.9.4.tar.gz

Special Issues
You may need to configure your terminal definitiosn to get the most out of GNU screen. See the files in the /usr/local/share/screen directory for more information.

See the main packages README for installation information.

User Manual

Screen User's Manual - Table of Contents

Reference

Manpage

[GNU screen manpage]

[Stolen pretty much verbatim from the man page. <PMG>]

Each window in a screen session emulates a VT100 terminal, with some extra functions added. The VT100 emulator is hardcoded; no other terminal types can be emulated.

Usually screen tries to emulate as much of the VT100/ANSI standard as possible. But if your terminal lacks certain capabilities, the emulation may not be complete. In these cases screen has to tell the applications that some of the features are missing. This is no problem on machines using termcap, because screen can use the $TERMCAP variable to customize the standard screen termcap.

But if you do a rlogin on another machine or your machine supports only terminfo this method fails. Because of this, screen offers a way to deal with these cases. Here is how it works:

When screen tries to figure out a terminal name for itself, it first looks for an entry named “screen.<term>”, where <term> is the contents of your $TERM variable. If no such entry exists, screen tries “screen” (or “screen-w” if the terminal is wide (132 cols or more)). If even this entry cannot be found, “vt100” is used as a substitute.

The idea is that if you have a terminal which doesn’t support an important feature (e.g. delete char or clear to EOS) you can build a new termcap/terminfo entry for screen (named “screen.<dumbterm>”) in which this capability has been disabled. If this entry is installed on your machines you are able to do a rlogin and still keep the correct termcap/terminfo entry. The terminal name is put in the $TERM variable of all new windows. Screen also sets the $TERMCAP variable reflecting the capabilities of the virtual terminal emulated. Notice that, however, on machines using the terminfo database this variable has no effect. Furthermore, the variable $WINDOW is set to the window number of each window.

The actual set of capabilities supported by the virtual terminal depends on the capabilities supported by the physical terminal. If, for instance, the physical terminal does not support underscore mode, screen does not put the us and ue capabilities into the window’s $TERMCAP variable, accordingly. However, a minimum number of capabilities must be supported by a terminal in order to run screen; namely scrolling, clear screen, and direct cursor addressing (in addition, screen does not run on hardcopy terminals or on terminals that overstrike).

Also, you can customize the $TERMCAP value used by screen by using the “termcap” .screenrc command, or by defining the variable $SCREENCAP prior to startup. When the is latter defined, its value will be copied verbatim into each window’s $TERMCAP variable. This can either be the full terminal definition, or a filename where the terminal “screen” (and/or “screen-w”) is defined.

Note that screen honors the “terminfo” .screenrc command if the system uses the terminfo database rather than termcap.

When the boolean ‘G0’ capability is present in the termcap entry for the terminal on which screen has been called, the terminal emulation of screen supports multiple character sets. This allows an application to make use of, for instance, the VT100 graphics character set or national character sets. The following control functions from ISO 2022 are supported: lock shift G0 (SI), lock shift G1 (SO), lock shift G2, lock shift G3, single shift G2, and single shift G3. When a virtual terminal is created or reset, the ASCII character set is designated as G0 through G3. When the G0 capability is present, screen evaluates the capabilities S0, E0, and C0 if present. S0 is the sequence the terminal uses to enable and start the graphics character set rather than SI. E0 is the corresponding replacement for SO. C0 gives a character by character translation string that is used during semi-graphics mode. This string is built like the acsc terminfo capability.

When the po and pf capabilities are present in the terminal’s termcap entry, applications running in a screen window can send output to the printer port of the terminal. This allows a user to have an application in one window sending output to a printer connected to the terminal, while all other windows are still active (the printer port is enabled and disabled again for each chunk of output). As a side-effect, programs running in different windows can send output to the printer simultaneously. Data sent to the printer is not displayed in the window. The info command displays a line starting ‘PRIN’ while the printer is active.

Screen maintains a hardstatus line for every window. If a window gets selected, the display’s hardstatus will be updated to match the window’s hardstatus line. If the display has no hardstatus the line will be displayed as a standard screen message. The hardstatus line can be changed with the ANSI Application Program Command (APC): ESC_<string>ESC\. As a convenience for xterm users the sequence ESC]0..2;<string>^G is also accepted.

Some capabilities are only put into the $TERMCAP variable of the virtual terminal if they can be efficiently implemented by the physical terminal. For instance, dl (delete line) is only put into the $TERMCAP variable if the terminal supports either delete line itself or scrolling regions. Note that this may provoke confusion, when the session is reattached on a different terminal, as the value of $TERMCAP cannot be modified by parent processes.

The “alternate screen” capability is not enabled by default. Set the altscreen .screenrc command to enable it.

The following is a list of control sequences recognized by screen. “(V)” and “(A)” indicate VT100-specific and ANSI- or ISO-specific functions, respectively.

ESC E Next Line
ESC D Index
ESC M Reverse Index
ESC H Horizontal Tab Set
ESC Z Send VT100 Identification String
ESC 7 (V) Save Cursor and Attributes
ESC 8 (V) Restore Cursor and Attributes
ESC [s (A) Save Cursor and Attributes
ESC [u (A) Restore Cursor and Attributes
ESC c Reset to Initial State
ESC g Visual Bell
ESC Pn p Cursor Visibility (97801)
Pn = 6 Invisible
7 Visible
ESC = (V) Application Keypad Mode
ESC > (V) Numeric Keypad Mode
ESC # 8 (V) Fill Screen with Es
ESC \ (A) String Terminator
ESC ^ (A) Privacy Message String (Message Line)
ESC ! Global Message String (Message Line)
ESC k A.k.a. Definition String
ESC P (A) Device Control String. Outputs a string directly to the host terminal without interpretation.
ESC _ (A) Application Program Command (Hardstatus)
ESC ] 0 ; string ^G (A) Operating System Command (Hardstatus, xterm title hack)
ESC ] 83 ; cmd ^G (A) Execute screen command. This only works if multi-user support is compiled into screen. The pseudo-user “:window:” is used to check the access control list. Use aclchg :window: -rwx #? to create a user with no rights and allow only the needed commands.
Control-N (A) Lock Shift G1(SO)
Control-O (A) Lock Shift G0 (SI)
ESC n (A) Lock Shift G2
ESC o (A) Lock Shift G3
ESC N (A) Single Shift G2
ESC O (A) Single Shift G3
ESC ( Pcs (A) Designate character set as G0
ESC ) Pcs (A) Designate character set as G1
ESC * Pcs (A) Designate character set as G2
ESC + Pcs (A) Designate character set as G3
ESC [ Pn ; Pn H Direct Cursor Addressing
ESC [ Pn ; Pn f same as above
ESC [ Pn J Erase in Display
Pn = None or 0 From Cursor to End of Screen
1 From Beginning of Screen to Cursor
2 Entire Screen
ESC [ Pn K Erase in Line
Pn = None or 0 From Cursor to End of Line
1 From Beginning of Line to Cursor
2 Entire Line
ESC [ Pn X Erase character
ESC [ Pn A Cursor Up
ESC [ Pn B Cursor Down
ESC [ Pn C Cursor Right
ESC [ Pn D Cursor Left
ESC [ Pn E Cursor next line
ESC [ Pn F Cursor previous line
ESC [ Pn G Cursor horizontal position
ESC [ Pn ' same as above
ESC [ Pn d Cursor vertical position
ESC [ Ps ;...; Ps m Select Graphic Rendition
Ps = None or 0 Default Rendition
1 Bold
2 (A) Faint
3 (A) Standout Mode (ANSI: Italicized)
4 Underlined
5 Blinking
7 Negative Image
22 (A) Normal Intensity
23 (A) Standout Mode off (ANSI: Italicized off)
24 (A) Not Underlined
25 (A) Not Blinking
27 (A) Positive Image
30 (A) Foreground Black
31 (A) Foreground Red
32 (A) Foreground Green
33 (A) Foreground Yellow
34 (A) Foreground Blue
35 (A) Foreground Magenta
36 (A) Foreground Cyan
37 (A) Foreground White
39 (A) Foreground Default
40 (A) Background Black
...
49 (A) Background Default
ESC [ Pn g Tab Clear
Pn = None or 0 Clear Tab at Current Position
3 Clear All Tabs
ESC [ Pn ; Pn r (V) Set Scrolling Region
ESC [ Pn I (A) Horizontal Tab
ESC [ Pn Z (A) Backward Tab
ESC [ Pn L (A) Insert Line
ESC [ Pn M (A) Delete Line
ESC [ Pn @ (A) Insert Character
ESC [ Pn P (A) Delete Character
ESC [ Pn S Scroll Scrolling Region Up
ESC [ Pn T Scroll Scrolling Region Down
ESC [ Pn ^ same as above
ESC [ Ps ;...; Ps h Set Mode
ESC [ Ps ;...; Ps l Reset Mode
Ps = 4 (A) Insert Mode
20 (A) Automatic Linefeed Mode
34 Normal Cursor Visibility
?1 (V) Application Cursor Keys
?3 (V) Change Terminal Width to 132 columns
?5 (V) Reverse Video
?6 (V) Origin Mode
?7 (V) Wrap Mode
?9 X10 mouse tracking
?25 (V) Visible Cursor
?47 Alternate Screen (old xterm code)
?1000 (V) VT200 mouse tracking
?1047 Alternate Screen (new xterm code)
?1049 Alternate Screen (new xterm code)
ESC [ 5 i (A) Start relay to printer (ANSI Media Copy)
ESC [ 4 i (A) Stop relay to printer (ANSI Media Copy)
ESC [ 8 ; Ph ; Pw t Resize the window to Ph lines and Pw columns (SunView special)
ESC [ c Send VT100 Identification String
ESC [ x Send Terminal Parameter Report
ESC [ > c Send VT220 Secondary Device Attributes String
ESC [ 6 n Send Cursor Position Report

Command line options

Screen has the following command-line options:

-a
include all capabilities (with some minor exceptions) in each window's termcap, even if screen must redraw parts of the display in order to implement a function.
-A
Adapt the sizes of all windows to the size of the current terminal. By default, screen tries to restore its old window sizes when attaching to resizable terminals (those with "WS" in its description, e.g. suncmd or some xterm).
-c file
override the default configuration file from "$HOME/.screenrc" to file.
-d|-D [pid.tty.host]
does not start screen, but detaches the elsewhere running screen session. It has the same effect as typing "Ctrl-a d" from screen's controlling terminal. -D is the equivalent to the power detach key. If no session can be detached, this option is ignored. In combination with the -r/-R option more powerful effects can be achieved:
-d -r
Reattach a session and if necessary detach it first.
-d -R
Reattach a session and if necessary detach or even create it first.
-d -RR
Reattach a session and if necessary detach or create it. Use the first session if more than one session is available.
-D -r
Reattach a session. If necessary detach and logout remotely first.
-D -R
Attach here and now. In detail this means: If a session is running, then reattach. If necessary detach and logout remotely first. If it was not running create it and notify the user. This is the author's favorite.
-D -RR
Attach here and now. Whatever that means, just do it.
Note: It is always a good idea to check the status of your sessions by means of "screen -list".
-e xy
specifies the command character to be x and the character generating a literal command character to y (when typed after the command character). The default is "Ctrl-a" and `a', which can be specified as "-e^Aa". When creating a screen session, this option sets the default command character. In a multiuser session all users added will start off with this command character. But when attaching to an already running session, this option changes only the command character of the attaching user. This option is equivalent to either the commands "defescape" or "escape" respectively.
-f, -fn, and -fa
turns flow-control on, off, or "automatic switching mode". This can also be defined through the "defflow" .screenrc command.
-h num
Specifies the history scrollback buffer to be num lines high.
-i
will cause the interrupt key (usually Ctrl-c) to interrupt the display immediately when flow-control is on. See the "defflow" .screenrc command for details. The use of this option is discouraged.
-l and -ln
turns login mode on or off (for /etc/utmp updating). This can also be defined through the "deflogin" .screenrc command.
-ls and -list
does not start screen, but prints a list of pid.tty.host strings identifying your screen sessions. Sessions marked `detached' can be resumed with "screen -r". Those marked `attached' are running and have a controlling terminal. If the session runs in multiuser mode, it is marked `multi'. Sessions marked as `unreachable' either live on a different host or are `dead'. An unreachable session is considered dead, when its name matches either the name of the local host, or the specified parameter, if any. See the -r flag for a description how to construct matches. Sessions marked as `dead' should be thoroughly checked and removed. Ask your system administrator if you are not sure. Remove sessions with the -wipe option.
-L
tells screen your auto-margin terminal has a writable last-position on the screen. This can also be set in your .screenrc by specifying `LP' in a "termcap" command.
-m
causes screen to ignore the $STY environment variable. With "screen -m" creation of a new session is enforced, regardless whether screen is called from within another screen session or not. This flag has a special meaning in connection with the `-d' option:
-d -m
Start screen in "detached" mode. This creates a new session but doesn't attach to it. This is useful for system startup scripts.
-D -m
This also starts screen in "detached" mode, but doesn't fork a new process. The command exits if the session terminates.
-O
selects a more optimal output mode for your terminal rather than true VT100 emulation (only affects auto-margin terminals without `LP'). This can also be set in your .screenrc by specifying `OP' in a "termcap" command.
-q
Suppress printing of error messages. In combination with "-ls" the exit value is as follows: 9 indicates a directory without sessions. 10 indicates a directory with running but not attachable sessions. 11 (or more) indicates 1 (or more) usable sessions. In combination with "-r" the exit value is as follows: 10 indicates that there is no session to resume. 12 (or more) indicates that there are 2 (or more) sessions to resume and you should specify which one to choose. In all other cases "-q" has no effect.
-r [pid.tty.host]
-r sessionowner/[pid.tty.host]
resumes a detached screen session. No other options (except combinations with -d/-D) may be specified, though an optional prefix of [pid.]tty.host may be needed to distinguish between multiple detached screen sessions. The second form is used to connect to another user's screen session which runs in multiuser mode. This indicates that screen should look for sessions in another user's directory. This requires setuid-root.
-R
attempts to resume the first detached screen session it finds. If successful, all other command-line options are ignored. If no detached session exists, starts a new session using the specified options, just as if -R had not been specified. The option is set by default if screen is run as a login-shell (actually screen uses "-xRR" in that case). For combinations with the -d/-D option see there.
-s
sets the default shell to the program specified, instead of the value in the environment variable $SHELL (or "/bin/sh" if not defined). This can also be defined through the "shell" .screenrc command.
-S sessionname
When creating a new session, this option can be used to specify a meaningful name for the session. This name identifies the session for "screen -list" and "screen -r" actions. It substitutes the default [tty.host] suffix.
-t name
sets the title (a.k.a.) for the default shell or specified program. See also the "shelltitle" .screenrc command.
-U
Run screen in UTF-8 mode. This option tells screen that your terminal sends and understands UTF-8 encoded characters. It also sets the default encoding for new windows to `utf8'.
-v
Print version number.
-wipe [match]
does the same as "screen -ls", but removes destroyed sessions instead of marking them as `dead'. An unreachable session is considered dead, when its name matches either the name of the local host, or the explicitly given parameter, if any. See the -r flag for a description how to construct matches.
-x
Attach to a not detached screen session. (Multi display mode).
-X
Send the specified command to a running screen session. You can use the -d or -r option to tell screen to look only for attached or detached screen sessions. Note that this command doesn't work if the session is password protected.

Random Findings

xmx: A Screen-ish program for X (2.75 / 4) (#95)
by froindlaven on Wed Mar 10, 2004 at 11:21:28 PM EST

Here's a cool X program which is both an X client and server. You can attach/detach to it much like screen. I tried it out when I had to jump around from lab machine to lab machine and it worked pretty well. In the end, I opted for just using ssh and screen.

dtach - A program that emulates the detach feature of screen

dtach is a tiny program that emulates the detach feature of screen, allowing you to run a program in an environment that is protected from the controlling terminal and attach to it later. dtach does not keep track of the contents of the screen, and thus works best with programs that know how to redraw themselves.

dtach does not, however, have the other features of screen, such as its support of multiple terminals or its terminal emulation support. This makes dtach extremely tiny compared to screen, making it more easily audited for bugs and security holes, and also allows it to fit in environments where space is limited, such as on rescue disks.

dtach has many possible uses, even though it is tiny. With dtach, you can:


The latest version of dtach is version 0.7, which you can fetch here. Other download formats may be available at the sourceforge download area for dtach.

The changes in version 0.7 are:

The changes in version 0.6 are: The changes in version 0.5 are: The changes in version 0.4 are: The changes in version 0.3 are: You can also obtain information on how to access the CVS tree here, and access the sourceforge project page here.

You can send any comments or questions about dtach to the author. Comments and suggestions are welcome.




Etc

FAIR USE NOTICE This site contains copyrighted material the use of which has not always been specifically authorized by the copyright owner. We are making such material available in our efforts to advance understanding of environmental, political, human rights, economic, democracy, scientific, and social justice issues, etc. We believe this constitutes a 'fair use' of any such copyrighted material as provided for in section 107 of the US Copyright Law. In accordance with Title 17 U.S.C. Section 107, the material on this site is distributed without profit exclusivly for research and educational purposes.   If you wish to use copyrighted material from this site for purposes of your own that go beyond 'fair use', you must obtain permission from the copyright owner.

Society

Groupthink : Two Party System as Polyarchy : Corruption of Regulators : Bureaucracies : Understanding Micromanagers and Control Freaks : Toxic Managers :   Harvard Mafia : Diplomatic Communication : Surviving a Bad Performance Review : Insufficient Retirement Funds as Immanent Problem of Neoliberal Regime : PseudoScience : Who Rules America : Neoliberalism  : The Iron Law of Oligarchy : Libertarian Philosophy

Quotes

War and Peace : Skeptical Finance : John Kenneth Galbraith :Talleyrand : Oscar Wilde : Otto Von Bismarck : Keynes : George Carlin : Skeptics : Propaganda  : SE quotes : Language Design and Programming Quotes : Random IT-related quotesSomerset Maugham : Marcus Aurelius : Kurt Vonnegut : Eric Hoffer : Winston Churchill : Napoleon Bonaparte : Ambrose BierceBernard Shaw : Mark Twain Quotes

Bulletin:

Vol 25, No.12 (December, 2013) Rational Fools vs. Efficient Crooks The efficient markets hypothesis : Political Skeptic Bulletin, 2013 : Unemployment Bulletin, 2010 :  Vol 23, No.10 (October, 2011) An observation about corporate security departments : Slightly Skeptical Euromaydan Chronicles, June 2014 : Greenspan legacy bulletin, 2008 : Vol 25, No.10 (October, 2013) Cryptolocker Trojan (Win32/Crilock.A) : Vol 25, No.08 (August, 2013) Cloud providers as intelligence collection hubs : Financial Humor Bulletin, 2010 : Inequality Bulletin, 2009 : Financial Humor Bulletin, 2008 : Copyleft Problems Bulletin, 2004 : Financial Humor Bulletin, 2011 : Energy Bulletin, 2010 : Malware Protection Bulletin, 2010 : Vol 26, No.1 (January, 2013) Object-Oriented Cult : Political Skeptic Bulletin, 2011 : Vol 23, No.11 (November, 2011) Softpanorama classification of sysadmin horror stories : Vol 25, No.05 (May, 2013) Corporate bullshit as a communication method  : Vol 25, No.06 (June, 2013) A Note on the Relationship of Brooks Law and Conway Law

History:

Fifty glorious years (1950-2000): the triumph of the US computer engineering : Donald Knuth : TAoCP and its Influence of Computer Science : Richard Stallman : Linus Torvalds  : Larry Wall  : John K. Ousterhout : CTSS : Multix OS Unix History : Unix shell history : VI editor : History of pipes concept : Solaris : MS DOSProgramming Languages History : PL/1 : Simula 67 : C : History of GCC developmentScripting Languages : Perl history   : OS History : Mail : DNS : SSH : CPU Instruction Sets : SPARC systems 1987-2006 : Norton Commander : Norton Utilities : Norton Ghost : Frontpage history : Malware Defense History : GNU Screen : OSS early history

Classic books:

The Peter Principle : Parkinson Law : 1984 : The Mythical Man-MonthHow to Solve It by George Polya : The Art of Computer Programming : The Elements of Programming Style : The Unix Hater’s Handbook : The Jargon file : The True Believer : Programming Pearls : The Good Soldier Svejk : The Power Elite

Most popular humor pages:

Manifest of the Softpanorama IT Slacker Society : Ten Commandments of the IT Slackers Society : Computer Humor Collection : BSD Logo Story : The Cuckoo's Egg : IT Slang : C++ Humor : ARE YOU A BBS ADDICT? : The Perl Purity Test : Object oriented programmers of all nations : Financial Humor : Financial Humor Bulletin, 2008 : Financial Humor Bulletin, 2010 : The Most Comprehensive Collection of Editor-related Humor : Programming Language Humor : Goldman Sachs related humor : Greenspan humor : C Humor : Scripting Humor : Real Programmers Humor : Web Humor : GPL-related Humor : OFM Humor : Politically Incorrect Humor : IDS Humor : "Linux Sucks" Humor : Russian Musical Humor : Best Russian Programmer Humor : Microsoft plans to buy Catholic Church : Richard Stallman Related Humor : Admin Humor : Perl-related Humor : Linus Torvalds Related humor : PseudoScience Related Humor : Networking Humor : Shell Humor : Financial Humor Bulletin, 2011 : Financial Humor Bulletin, 2012 : Financial Humor Bulletin, 2013 : Java Humor : Software Engineering Humor : Sun Solaris Related Humor : Education Humor : IBM Humor : Assembler-related Humor : VIM Humor : Computer Viruses Humor : Bright tomorrow is rescheduled to a day after tomorrow : Classic Computer Humor

The Last but not Least


Copyright © 1996-2014 by Dr. Nikolai Bezroukov. www.softpanorama.org was created as a service to the UN Sustainable Development Networking Programme (SDNP) in the author free time. This document is an industrial compilation designed and created exclusively for educational use and is distributed under the Softpanorama Content License. Site uses AdSense so you need to be aware of Google privacy policy. Original materials copyright belong to respective owners. Quotes are made for educational purposes only in compliance with the fair use doctrine.

FAIR USE NOTICE This site contains copyrighted material the use of which has not always been specifically authorized by the copyright owner. We are making such material available to advance understanding of computer science, IT technology, economic, scientific, and social issues. We believe this constitutes a 'fair use' of any such copyrighted material as provided by section 107 of the US Copyright Law according to which such material can be distributed without profit exclusively for research and educational purposes.

This is a Spartan WHYFF (We Help You For Free) site written by people for whom English is not a native language. Grammar and spelling errors should be expected. The site contain some broken links as it develops like a living tree...

You can use PayPal to make a contribution, supporting hosting of this site with different providers to distribute and speed up access. Currently there are two functional mirrors: softpanorama.info (the fastest) and softpanorama.net.

Disclaimer:

The statements, views and opinions presented on this web page are those of the author and are not endorsed by, nor do they necessarily reflect, the opinions of the author present and former employers, SDNP or any other organization the author may be associated with. We do not warrant the correctness of the information provided or its fitness for any purpose.

Last modified: November 25, 2014