Screen – screen manager with VT100/ANSI terminal emulation

By jbayer - Last updated: Sunday, December 5, 2010 - Save & Share - Leave a Comment

Screen is a full-screen window manager that multiplexes a physical terminal between several processes (typically interactive shells). Each virtual terminal provides the functions of a DEC VT100 terminal and, in addition, several control functions from the ISO 6429 (ECMA 48, ANSI X3.64) and ISO 2022 standards (e.g. insert/delete line and support for multiple character sets). There is a scrollback history buffer for each virtual terminal and a copy-and-paste mechanism that allows moving text regions between windows.

When screen is called, it creates a single window with a shell in it (or the specified command) and then gets out of your way so that you can use the program as you normally would. Then, at any time, you can create new (full-screen) windows with other programs in them (including more shells), kill existing windows, view a list of windows, turn output logging on and off, copy-and-paste text between windows, view the scrollback history, switch between windows in whatever manner you wish, etc. All windows run their programs completely independent of each other. Programs continue to run when their window is currently not visible and even when the whole screen session is detached from the user’s terminal. When a program terminates, screen (per default) kills the window that contained it. If this window was in the foreground, the display switches to the previous window; if none are left, screen exits.

A simple use of screen is as follows:

To start a screen session, use the following command:

screen

You may get a screen of text describing the program, the license etc.  If you get this screen, just press the <Return> key to continue.  The screen will be cleared and you will then get a normal command prompt.  You are now inside of a window within the screen program.  This functions just like a normal shell except for a few special characters. Screen uses the command “Ctrl-A” as a signal to send commands to screen instead of the shell. To get help, just use “Ctrl-A” then “?”. You should now have the screen help page.

The following are the most common commands used during a screen session:

<Ctrl-A> ?     Display the help screen(s)
<Ctrl-A> *     List the current screens
<Ctrl-A> c     Create a new screen
<Ctrl-A> n    Next screen
<Ctrl-A> p    Previous screen
<Ctrl-A> H    Create a running log of the session
<Ctrl-A> K    Kill the current screen.  This will kill the current windows. If you have other windows, you will drop into one of those. If this is the last window, then you will exit screen.

Another way to leave the screens is o detach from a windows. This method leaves the process running and simple closes the window. If you have really long processes, you need to close your SSH program, you can detach from the window using

<Ctrl-A> d

This will drop you into your shell. All screen windows are still there and you can re-attach to them later.

So you are using screen now and compiling that program. It is taking forever and suddenly your connection drops. Don’t worry screen will keep the compilation going. Login to your system and use the screen listing tool to see what sessions are running:

screen -ls

To reattach to a screen, you use the following command:

screen -r  [screen session]

If there is only a single screen session running, you don’t need to specify the session name;  otherwise you get the session name from the “screen -ls” command.

The logging function is very useful. Once started, screen will keep appending data to the file through multiple sessions. Using the log function is very useful for capturing what you have done, especially if you are making a lot of changes. If something goes awry, you can look back through your logs.

This only covers the most common uses of screen.  It has a lot more power, to learn more, use the man pages to get additional information.

Posted in Administration, Linux commands • • Top Of Page
3,240 views

Write a comment

asd