Screen use. Screen launch and basics. Disconnecting from screen

5,958 views

The creators of Screen call the utility a (pseudo) terminal manager. The idea is to provide access to these terminals from a single terminal, as if we were working in a "real" TTY and switch from one to another with the Alt- Fn.

In fact, Screen does a lot more. I will list two of its main advantages.


Rice. 2. Both pseudo-terminals in one Screen window (top) instead of two separately open windows (bottom).

Before proceeding to the description of the utility, it will be useful to agree on terminology, following which makes it easier to understand how Screen works.

1. Terms and definitions

Window- a pseudo-terminal with its own bash (nonlogin). Windows are numbered from 0 to 9 (window numbers can be redefined). They can (and preferably) be named.

Region- a rectangular area of ​​the screen in which one of the windows is displayed. The screen can be divided into areas both vertically and horizontally.

Screen layout (layout). This is a set of areas into which the terminal screen is split. Each layout can be given a name and added to the configuration file to be able to quickly select them within the Screen session using the layout commands group (see below).

2. Description of commands

Control keyboard shortcuts. To switch to the mode of entering control commands in screen, Ctrl-a is used by default. After pressing this combination, the actual control character or combination is entered, for example? (command help) or Ctrl-I (move to next area). For the sake of simplicity, in what follows, only the control shortcuts themselves will be mentioned without the Ctrl-a switch.

Working with windows (pseudo-terminals, PTS) withCreate a window with bash running in it.KClose a windowARename windowrEnable / Disable Line Wrapping in Terminal" List windows Working with regions of the screen sSplit an area in two horizontallyI (pipe)Split an area in two verticallyTabSwitch to the next area of ​​the screenQClose all other areas and keep current (which is the focus) Working with Screen sessions dBring the session to the background and return to the system console

Internal Screen commands. Available after entering the control character: (colon).

mousetrack onEnable mouse support for switching between areas. At the same time, the ability to copy / paste by right-clicking the mouse in the Putty ssh client window is blocked. For some reason this function disappears after "detaching" the Screen session and returning to it.layout showView a list of screen layouts defined in the configuration filelayout selectSelect the named screen layout specified in the configuration file either by number (n) or by title (title).layout save XXXThis command must be executed to save the current layout with the name XXX before detaching the Screen session, if there is no named markup in the configuration file (for example, you just installed screen). Only in this case, the last markup is restored when you re-enter the Screen session from the system console.layout autosave onThe autosave markup command is usually written in a configuration file. It remembers the named layout that was on the screen when the Screen session was "detached". The command acts only on markings that are explicitly specified in the configuration file. Otherwise, the current layout must be saved with the layout save XXX command (see above).quitClose all windows and end session

/ * Here you can add custom CSS for the current table * / / * Lean more about CSS: https://en.wikipedia.org/wiki/Cascading_Style_Sheets * / / * To prevent the use of styles to other tables use "# supsystic-table-1 "as a base selector for example: # supsystic-table-1 (...) # supsystic-table-1 tbody (...) # supsystic-table-1 tbody tr (...) * /

3. Example configuration file .screenrc

The global screen configuration file is located at / etc / screenrc, but for convenience it is better to write a custom file that should be located in the user's home directory ~ / .screenrc. Note that there is a dot at the beginning of the local file name.

As a basis, I took the file from Github (.screenrc by joaopizani) and tweaked it to fit my needs:


Thus, when Screen starts, we get a Total Commander-style screen, which can be changed at any time by choosing a different layout. After returning to the Screen session from the system console, the markup will be the same as it was at the time of "detach" thanks to the autosave function.

Screen is a very handy program if you often work in the console by connecting to the server via SSH. In this case screen allows you to keep several different screens in one console, conveniently switching between them.

Installing screen

To install on, you need to run the command

$ sudo apt-get install screen

After that, you need to run screen:

$ screen

After starting, you will see either a command line prompt or a "welcome screen" by pressing SPACE or ENTER in which, you will also be taken to the shell. In this case, all commands will be launched already "inside" the screen.

If you need to listen to the log file constantly and display them on the screen. Let's create a new console screen like this:

Screen -d -m -S tail-log tail -f /var/log/nginx/error.log

In order to exit the screen (exit, not detach), it is enough to exit all the shells open in it, or press the key combination Ctrl + A, and answer "y" to the question "do you really want to quit".

You can disconnect from the current screen without closing or ending the session with the combination Ctrl + A then d.

Screen connection

If the machine already has a running screen session and you want to connect to it, then

  1. if there is only one session, a simple command is enough: Ctrl + A then x
  2. if there are several sessions, then: you can view the list of running screens using the screen -ls command: $ screen -ls There are screens on: 2762.pts-0.debian (Detached) 2743.pts-0.debian (Detached) 2 Sockets in / var / run / screen / S-diesel.

    Select the screen we need, and attach to it:

    Screen -x 2762.pts-0.debian

    Session names are not very informative by default - just process numbers, if you want to start and use several screen sessions for different tasks, you can come up with more sane names. We come up with a name, then start a new screen like this:

    $ screen -S "job1"

    where job1 is the name of our named session. Now in -ls we will see much more clear:

    $ screen -ls There are screens on: 2762.pts-0.debian (Detached) 2795.job1 (Detached) 2743.pts-0.debian (Detached) 3 Sockets in / var / run / screen / S-diesel.

    and we can connect to the job1 session simply by specifying its name:

    $ screen -x job1

Switching between screens

As you already understood, sessions are saved even while you are disconnected from the server, and everything that is running in them continues to run. However, the screen's possibilities are not limited to this. Sometimes, when working via ssh, I really want several terminals to be open at once. Screen can help with this too.

Ctrl + A then?- display all available commands and parameters, to exit a space or Enter
Ctrl + A then c- create create window screen
Ctrl + A then p- strongvios switch to the previous screen
Ctrl + A then n- next switch to the next window screen
Ctrl + A then d- deatached disconnect from screen leaving the session running
Ctrl + A then K- kill kill the screen session
Ctrl + A then x- screen lock, you need to enter Linux password to unlock.
Ctrl + A then w- a list of windows running in the screen
Ctrl + A then A- sign the name of different windows in the screen
Ctrl + A then |- split windows vertically, after Ctrl + A a vertical bar (not small L) or type split -v
Ctrl + A then S- split windows horizontally
Ctrl + A then Tab- transition between halves
Ctrl + A Q- hide all windows and leave only the current one
Ctrl + D- exit the screen session

Copy text between windows and scroll the screen

Ctrl + A then [- will switch the screen to Copy mode, while you can move around the window with the cursor keys, to determine the beginning of a text fragment, press the space bar. Moving the cursor arrows, mark the end of the selection and press the spacebar again. That's it, the fragment is copied. It is inserted into the same or another window by pressing ] .

To exit this mode, simply press Esc.

Monitoring command execution

If several windows are open, it can be useful to be able to monitor the activity in one of them. For example, if you run a command and are wondering when it will complete. Go to the window with this command, click

Ctrl + A then m- and enable monitoring of window activity. Now if the text of the window changes, the screen will sound a beep, the “@” symbol will be displayed in the list of windows next to its name, and the inscription “Activity in the window №…” will appear at the bottom of the window for a few seconds!

Logging and print screen

It is also possible to trace all the text output to the window into a special screenlog file. where N is the window number.

Ctrl + A then H

Now all the results of your work will be logged and you can see the history of not only input, but also output.

Also the command for removing the current window

Ctrl + A then h

transfers to file hardcopy. only the contents of the current window, rather than constantly monitoring I / O. Analogue of a print-screen.

Screen configuration

Screen is configured with the ~ / .screenrc file in your home directory. For example, you can write there:

Caption always "% (= 45)% (+ bw) Screen:% n |% h% =% t% c" hardstatus alwayslastline "% -Lw% (= BW)% 50>% n% f *% t% ( -)% + Lw%<"

This will give you an all-time visible list of open windows, and other useful information at the bottom of the screen.

Also, when Screen starts, by default, commands from the / etc / screenrc file and the .screenrc file from the user's home directory are executed. Many commands that can be used in configuration files were discussed in the tables above in the "Text command" field. Below is an example of a Screen configuration from a .screenrc file:

# Disable the output of license information at startup Screen startup_message off # Open a shell for working chdir screen -t Work # Open a shell for managing configuration chdir / etc screen -t Configuration # Open a shell for viewing logs chdir / var / log screen -t Logs # Select first window after start select 0

This fairly simple configuration file opens three windows named Work, Configuration, Logs, respectively, in the user's personal directory, in the / etc directory, and in the / var / log directory. After launch, the screen will display the first window named Work. Figure 1 shows an example of how Screen works with this configuration file.

Screen Completion

If for some reason the screen session becomes unresponsive, you can terminate it. To do this, you need to connect to the desired session, then click Ctrl + A and enter the command ": quit".

Screen is a console application that allows you to use multiple terminal sessions in one window. The program acts within a shell session and acts as a container and manager for other terminal sessions, much like a window manager manages windows.

In many cases, creating multiple terminal windows is not possible. You may need to manage multiple console sessions without starting the X server; you may need to quickly access several remote cloud servers or display a running program on the monitor while working on some other task. All of these needs are easily met with the Screen Console.

Installation

This tutorial uses Ubuntu 12.04; on every modern distribution, all commands except installation will be the same.

To install the console on Ubuntu, use the "apt-get" command:

sudo apt-get update
sudo apt-get install screen

Basics of use

To start a screen session, simply call the "screen" command:

screen
Screen version 4.00.03jw4 (FAU) 2-May-06
Copyright (c) 1993-2002 Juergen Weigert, Michael Schroeder
Copyright (c) 1987 Oliver Laumann
This program is free software; you can redistribute it and / or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 2, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program (see the file COPYING); if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Send bugreports, fixes, enhancements, t-shirts, money, beer & pizza to
[email protected]

The licensing page will appear on startup. Press Return or Enter to continue.

Further actions of the program may be unexpected. The normal command line is provided and nothing seems to happen. Is there an error with screen? To find out, use the keyboard shortcut. Press and hold the control key (Ctrl), press "a", then the "v" key:

This action asks Screen for version information; the displayed result indicates that the console is working.

Now you need to familiarize yourself with console management. Screen is controlled primarily by keyboard shortcuts. Each such combination must be preceded by "Ctrl-a" (hold down the "Ctrl" key before pressing "a"). This keystroke sequence tells Screen to pay attention to the next keystroke.

This principle has already been used when requesting information about Screen. Use it again to get some more useful information.

Ctrl-a?
Screen key bindings, page 1 of 2.
Command key: ^ A Literal ^ A: a
break ^ B b license, removebuf =
clear C lockscreen ^ X x reset Z
colon: log H screen ^ C c
copy ^ [[login L select "
detach ^ D d meta a silence _
digraph ^ V monitor M split S
displays * next ^ @ ^ N sp n suspend ^ Z z
dumptermcap. number N time ^ T t
fit F only Q title A
flow ^ F f other ^ A vbell ^ G
focus ^ I pow_break B version v
hardcopy h pow_detach D width W
help? prev ^ H ^ P p ^? windows ^ W w
history () quit \ wrap ^ R r
info i readbuf< writebuf >
kill K k redisplay ^ L l xoff ^ S s
lastmsg ^ M m remove X xon ^ Q q

This is a list of internal hotkeys. It's worth remembering the command to invoke it, as it's a great way to get help quickly. As you can see at the bottom of the file, to get more commands, you need to press the space bar.

Now call the "top" command, which provides information about the processes.

top
top - 16:08:07 up 1:44, 1 user, load average: 0.00, 0.01, 0.05
Tasks: 58 total, 1 running, 57 sleeping, 0 stopped, 0 zombie
Cpu (s): 0.0% us, 0.0% sy, 0.0% ni, 100.0% id, 0.0% wa, 0.0% hi, 0.0% si, 0.0% st
Mem: 507620k total, 262920k used, 244700k free, 8720k buffers
Swap: 0k total, 0k used, 0k free, 224584k cached
PID USER PR NI VIRT RES SHR S% CPU% MEM TIME + COMMAND
1 root 20 0 3384 1836 1288 S 0.0 0.4 0: 00.70 init
2 root 20 0 0 0 0 S 0.0 0.0 0: 00.00 kthreadd
3 root 20 0 0 0 0 S 0.0 0.0 0: 00.11 ksoftirqd / 0
5 root 20 0 0 0 0 S 0.0 0.0 0: 00.12 kworker / u: 0
6 root RT 0 0 0 0 S 0.0 0.0 0: 00.00 migration / 0
7 root RT 0 0 0 0 S 0.0 0.0 0: 00.07 watchdog / 0
8 root 0 -20 0 0 0 S 0.0 0.0 0: 00.00 cpuset
9 root 0 -20 0 0 0 S 0.0 0.0 0: 00.00 khelper
10 root 20 0 0 0 0 S 0.0 0.0 0: 00.00 kdevtmpfs
11 root 0 -20 0 0 0 S 0.0 0.0 0: 00.00 netns
12 root 20 0 0 0 0 S 0.0 0.0 0: 00.03 sync_supers
13 root 20 0 0 0 0 S 0.0 0.0 0: 00.00 bdi-default
14 root 0 -20 0 0 0 S 0.0 0.0 0: 00.00 kintegrityd
15 root 0 -20 0 0 0 S 0.0 0.0 0: 00.00 kblockd
16 root 0 -20 0 0 0 S 0.0 0.0 0: 00.00 ata_sff
17 root 20 0 0 0 0 S 0.0 0.0 0: 00.00 khubd
18 root 0 -20 0 0 0 S 0.0 0.0 0: 00.00 md

Now you can view the processes on the VPS. But what commands should you use to get more detailed information about running programs? You don't have to leave the "top" command, but just create a new window to run these commands.

The sequence "Ctrl-a c" creates a new window. Now you can run any command without breaking the commands running in another window (in this case, monitoring processes).

Where has this other window gone? You can return to it using the command:

This sequence displays the next launched window. The window list is looped around, so if there are no other windows behind the current window, it returns the first window.

This sequence switches windows in reverse order. If, for example, three windows are running, and the third is the current one, this command will display a second window.

When constantly switching between two windows, it is useful to use the following keyboard shortcut:

This sequence takes the user to the most frequently visited window. In the previous example, it would bring up the third window again.

At this time, keeping track of all the windows created may seem impossible. Fortunately, the Screen console provides several ways to manage different sessions. First, create three new windows (for a total of 4 windows), and then use one of the simplest windowing tools - "Ctrl-a w".

Ctrl-a c
Ctrl-a c
Ctrl-a c
Ctrl-a w
0 $ bash 1 $ bash 2- $ bash 3 * $ bash

This command provides useful information - a list of open windows. In this case, 4 windows are open. Each window is numbered starting at 0. An asterisk next to the number indicates the current window.

As you can see, at the moment window # 3 is the current one (in fact, it is the fourth one, since the numbering starts from 0). How to quickly switch to window # 1?

The sequence number can be used to go directly to the required window. Open the window list again:

Ctrl-a w
0 $ bash 1 * $ bash 2 $ bash 3- $ bash

As you can see, now window # 1 is the current one. Try another way to switch between windows.

Ctrl-a “
Num Name Flags
0 bash $
1 bash $
2 bash $
3 bash $

This time the navigation menu is displayed. You can now navigate using the up and down arrows, or the j and k keys, as you do in the vi text editor. You can switch to the selected window by pressing the "Return" or "Enter" button.

This is useful enough, but for now all windows are named "bash". This is not very convenient. Now we need to name the session. Switch to the window you want to name and use the sequence "Ctrl-a A".

Ctrl-a 0
Ctrl-a A
Set window "s title to: bash

This sequence can be used to name the session. Use the backspace key to erase bash and enter any new name. For example, name window # 0 "monitoring" and run the "top" command in it.

Set window "s title to: monitoring
Ctrl-a “
Num Name Flags
0 monitoring $
1 bash $
2 bash $
3 bash $

Window # 0 has a more convenient name.

Now you can create and rename windows; but how to get rid of the unnecessary window?

Use the sequence "Ctrl-a k" which means "kill":

Ctrl-a k
Really kill this window

Screen Session Management

To exit Screen and close all windows, use the following sequence of commands:

Ctrl-a \
Really quit and kill all your windows

This will end the Screen session. All created windows as well as all work in progress will be lost.

Using Screen has one huge advantage. The session can not be deleted, but simply removed. Deleting a session allows programs running in Screen to continue working, and also gives access to the session of the main console (the one from which you start working with Screen). This Screen session still exists, it just runs in the background.

Ctrl-a d

So the session has been canceled. How do I return to this session?

The "-r" flag means "reattach" or "restore". But what if there are multiple Screen sessions? What if a Screen session was created and captured, and then a new session was created that was also captured?

screen
Ctrl-a d
screen
Ctrl-a d

How do I tell Screen which session to restore?

screen –ls
There are screens on:
2171.pts-0.Blank (07/01/2013 05:00:39 PM) (Detached)
1835.pts-0.Blank (07/01/2013 03:50:43 PM) (Detached)
2 Sockets in / var / run / screen / S-justin.

The list of sessions is now displayed. To restore the second session, enter its identification number after the "-r" flag.

screen –r 1835

What if you need to restore a session on two remote computers or terminal windows? Use the "-x" flag to split the session.

Terminal control in Screen

There are a number of commands that allow you to manage terminal sessions running in Screen.

To copy the text, use the sequence:

This sequence provides a cursor that can be moved using the arrow keys or the h, j, k, l keys (as in vi). Move your cursor to the beginning of the piece of text you want to copy and press Return or Enter. Then move the cursor to the end of the fragment and press "Return" or "Enter" again. The text will be copied to the clipboard.

Remember that this is also the scrolling mechanism for this console. If you want to view off-screen text, enter "Ctrl-a [" and scroll up.

You can paste copied text with a closing square bracket

You may also need to view programs running in another screen window.

For example, some data is compiled in one window and you need to know when the procedure is completed. You can tell Screen to keep track of the inactivity of this window using the "Ctrl-a _" sequence, which will tell you if the data is no longer displayed within 30 seconds.

Let's give a simpler example. Tell the Screen console to report when the window has finished pinging Google 4 times.

ping –c 4 www.google.com
Ctrl-a _
The window is now being monitored for 30 sec. silence.

Now you can work in another window and wait for the task completion notification in the previous window.

Ctrl-a 1
Window 2: silence for 30 seconds

Alternatively, you can request notification of the activity of a specific window. This is done using the sequence "Ctrl-a M".

sleep 20 && echo "output"
Ctrl-a M
Window 2 (bash) is now being monitored for all activity.

A notification will now appear when outputting data in this window.

Ctrl-a 1
Activity in window 2

For example, you need to make a number of important changes, and you need to get a log of the running commands. The session can be recorded using:

Ctrl-a H
Creating logfile "screenlog.1".

Screen Areas

If you need to see several windows at once, you can use the so-called "areas". New regions are created by splitting the current region. To split the current region horizontally, you can enter:

This will move the current window to the top of the screen and open a new blank area below it. To move to the bottom area, use "tab":

Now in the lower area you can create a new window or switch to another window in the usual way.

If you want to destroy the current region, use the following sequence:

This removes the area without destroying the current window. That is, if a command was launched in this area, then you can still access it like a normal window, just a separate area is destroyed.

If you need to make a vertical section, you can use the sequence:

Note: this is not the 1 (one) or L character. This is the pipe character, which on most keyboards sits on the same key as the "\" character. The controls for vertical areas are the same as controls for horizontal areas. If you need to delete several different areas and return to one area, you can use this sequence, which destroys all areas except the current one:

Using Byobu

A significant improvement for Screen is a program called "byobu". It acts as a wrapper for Screen and provides increased usability. On Ubuntu, you can install it using:

sudo apt-get install byobu

Before we start, we need to tell byobu to use screen as an output buffer. This can be done with the command:

byobu-select-backend
Select the byobu backend:
1.tmux
2.screen
Choose 1-2:

Here you can set screen as your default terminal manager.

Now you can enter "byobu" instead of "screen" to start the session.

byobu
Welcome to Ubuntu 12.04 LTS (GNU / Linux 3.2.0-24-virtual i686)
* Documentation: https://help.ubuntu.com/
Welcome to the light, powerful, text window manager, Byobu.
You can toggle the launch of Byobu at login with:
"byobu-disable" and "byobu-enable"
For tips, tricks, and more information, see:
* http://bit.ly/byobu-help
[email protected]:~$
u? 12.04 0: * 118! 3h55m 2.00 2.0GHz 496M6% 2013-07-01 18:19:21

As you can see, screen is now wrapped in a user-friendly interface.

The first time you type "Ctrl-a", you tell byobu to recognize this command as a screen command, not Emacs.

Ctrl-a
Configure Byobu "s ctrl-a behavior ...
When you press ctrl-a in Byobu, do you want it to operate in:
(1) Screen mode (GNU Screen "s default escape sequence)
(2) Emacs mode (go to beginning of line)
Note that:
- F12 also operates as an escape in Byobu
- You can press F9 and choose your escape character
- You can run "byobu-ctrl-a" at any time to change your selection
Select:

Select 1 to use byobu normally.

The interface provides a lot of useful information such as a list of windows and information about the system. On Ubuntu, it even reports how many packages have security updates as a number followed by an exclamation mark on a red background.

The only difference between byobu and screen is that byobu manages sessions. If, after disconnecting, simply typing "byobu" again, it will restore the previous session instead of creating a new one.

To create a new session, you need to type:

byobu –S sessionname

Change the "sessionname" (session name) to your liking to invoke a new session. The list of current sessions can be viewed using:

byobu –ls
There are screens on:
22961.new (07/01/2013 06:42:52 PM) (Detached)
22281.byobu (07/01/2013 06:37:18 PM) (Detached)
2 Sockets in / var / run / screen / S-root.

If there are several sessions, then after entering "byobu" a menu will appear in which you can choose which of the sessions you want to connect to.

byobu
Byobu sessions ...
1.screen: 22961.new (07/01/2013 06:42:52 PM) (Detached)
2.screen: 22281.byobu (07/01/2013 06:37:18 PM) (Detached)
3. Create a new Byobu session (screen)
4. Run a shell without Byobu (/ bin / bash)
Choose 1-4:

You can select any of the existing sessions, create a new byobu session, or even a new shell that does not use byobu.

One of the very useful features for a remote cloud server is the ability to launch byobu automatically every time you connect to a session. This means that when you disconnect a session, work will not be lost, and you can easily connect to this session again.

To enable byobu to start automatically on every login, type in the terminal:

byobu-enable
The Byobu window manager will be launched automatically at each text login.
To disable this behavior later, just run:
byobu-disable
Press to continue ...

As stated above, to disable this feature, simply enter:

Then it will not start automatically.

Tags:,

S creen is a very useful command that offers the ability to use multiple shell windows (sessions) from one. When the session is disconnected or there is a network outage, the process that starts in the screen session will still work, and you can reconnect to the screen session at any time. It's also very handy if you want to run a long process all the time or connect to the session shell from multiple locations.

In this article, we will show you the basics of installing and using the screen on.

How to install the screen

The screen comes preinstalled on some of the popular distributions. You can check whether it is installed on the server or not with the following command

Screen -v Screen version 4.00.03 (FAU)

If you do not have a VPS screen, you can easily install it using the package manager provided with the operating system.

/ RedHat / Fedora

yum -y install screen

/

apt-get -y install screen

How to start a screen session

You can start the screen by typing the word “screen” at the command line and a new screen session will be launched, which looks the same as on the command line

It is good practice to start screen sessions with descriptive names so that you can easily remember what process is running in the session. To create a new session with a session name run the following command

Screen -S name

and replace ‘ name‘With a self-explanatory name for your session.

Detach screen from session

To disconnect from the current screen session, you can press the ‘ Ctrl-A' and ' D' on keyboard. All screen sessions will remain active and you can reconnect to them at any time later.

Re-enter the session screen

If you are disconnected from your session or your connection is interrupted for some reason, you can easily reconnect by running the following command:

Screen -r

If you have multiple screen sessions you can list them with ‘’

Screen -ls There are screens on: 7880.session (Detached) 7934.session2 (Detached) 7907.session1 (Detached) 3 Sockets in / var / run / screen / S-root.

In our example, we have three active screen sessions. So, if you want to restore the “session2” session, you can do

Screen -r 7934

or you can use the screen name

Screen -r -S session2

End screen session

There are several ways to end your screen session. You can do this by clicking ‘ Ctrl‘ + ‘ D'On the keyboard or using the command line command' exit‘.

You can check the man page screen to see all the useful properties of the command screen.

Man screen NAME screen - screen manager with VT100 / ANSI terminal emulation SYNOPSIS screen [-options] [cmd [args]] screen -r] screen -r sessionowner /]

Screen is a full-screen program that can be used to multiplex a physical console between multiple processes (usually interactive shells). It prompts the user to open multiple separate terminals in a single terminal window manager.

On my Ubuntu 10.04 Server Edition, Screen was installed by default. But, Linux Mint doesn't have Screen by default, I need to install it first using the apt-get command. Please follow the screen installation process for your distribution.

# apt-get install screen (On Debian based Systems) # yum install screen (On RedHat based Systems)

In fact, Screen is a very good Linux command hidden inside hundreds of Linux commands. Let's start to see the Screen features.

Launching Screen for the first time

Just enter screen at the command line. Then screen will appear with the same interface as on the command line.

[email protected]~ $ screen

Show screen options

Once you enter screen, you can perform various actions just like in a normal CLI environment. But since screen is an application, so it has commands or parameters.

Dial Ctrl-A and ? ... You will now see all commands or options on the screen.

Screen key bindings, page 1 of 1. Command key: ^ A Literal ^ A: a break ^ B b flow ^ F f lockscreen ^ X x pow_break B screen ^ C c width W clear C focus ^ I log H pow_detach D select " windows ^ W w colon: hardcopy h login L prev ^ H ^ P p ^? silence _ wrap ^ R r copy ^ [[help? meta a quit \ split S writebuf> detach ^ D d history () monitor M readbuf< suspend ^Z z xoff ^S s digraph ^V info i next ^@ ^N sp n redisplay ^L l time ^T t xon ^Q q displays * kill K k number N remove X title A dumptermcap . lastmsg ^M m only Q removebuf = vbell ^G fit F license , other ^A reset Z version v ^] paste . " windowlist -b - select - 0 select 0 1 select 1 2 select 2 3 select 3 4 select 4 5 select 5 6 select 6 7 select 7 8 select 8 9 select 9 I login on O login off ] paste .

To exit this screen, you need to click on the " spaces" or " Enter". (Note that all shortcuts that use" Ctrl-A"are used without quotes).

Disable screen

One of the advantages of screen is that it can be turned off. Then you can restore it without losing the information you were doing before. Here's a sample script:

You are in the middle SSH-on on your server. Let's assume you are downloading a 400MB patch for your system using the command wget.

The download process will take about two hours. If you disable SSH session or disconnect due to an accident, the download process will stop. You will have to start over. To avoid this, we can use screen and disable it.

Take a look at this command. First, you must be logged into screen.

[email protected]~ $ screen

Then you can create a download process. For example, on my Linux Mint, I upgraded my dpkg package using the command apt-get.

[email protected]~ $ sudo apt-get install dpkg

Sample output

Reading package lists ... Done Building dependency tree Reading state information ... Done The following packages will be upgraded: dpkg 1 upgraded, 0 newly installed, 0 to remove and 1146 not upgraded. Need to get 2,583 kB of archives. After this operation, 127 kB of additional disk space will be used. Get: 1 http://debian.linuxmint.com/latest/ testing / main dpkg i386 1.16.10 47% 14.7 kB / s

" and " d". You will not see anything when you press these keys. The result will look like this:

[email protected] ~ $

Turn screen back on

After you have disabled screen, for example, we will assume that you have terminated SSH session and went home. At home you run SSH back to your server, and you want to see the download progress. To do this, you need to restore screen. You can run the following command:

[email protected]~ $ screen -r

And you will see that the process has resumed from the point where you interrupted it.

If you have more than 1 screen session, you need to enter the screen session ID. Use screen -ls to see how many screens are available.

[email protected]~ $ screen -ls

Sample output

[email protected]~ $ screen -ls There are screens on: 7849.pts-0.mint (10/06/2013 01:50:45 PM) (Detached) 5561.pts-0.mint (10/06/2013 11:12: 05 AM) (Detached) 2 Sockets in / var / run / screen / S-pungki

Restore screen if you want. 7849.pts-0.mint, then enter this command.

[email protected]~ $ screen -r 7849

Using multiple screens

Is it possible to run more than 1 screen to get the job done? Yes. You can work with multiple display windows at the same time. There are 2 (two) ways to do this.

First, you can detach the first screen and launch another screen on the terminal. Second, you are nesting screen.

Switching between screen

When you have nested screens, you can switch between them with the command " Ctrl-A" and " n". This will go to the next screen. When you need to return to the previous screen, press" Ctrl-A" and " p".

To create a new screen window, just click " Ctrl-A" and " with".

The login you do

It is sometimes important to write down what you did while you were at the console. Let's say you are a Linux administrator who manages many Linux servers.

With the login screen, you don't need to record every command you make. To activate the screen registration function simply press "strong> Ctrl-A" and " H". (Please be careful, we use a capital letter H... Using a small letter h will only create a screenshot of the screen in a separate file).

A notification appears at the bottom left of the screen that says: Creating logfile “ screenlog.0“. You'll find screenlog.0 file in your home directory.

This function will add whatever you do when you are in the screen window. Close the screen to login, press " Ctrl-A" and " H" again.

[email protected]~ $ screen -L

Another way to activate the logging function is to add the parameter " -L"when screen is first run. The command will look like this.

[email protected]~ $ screen -L

Screen lock

Screen is also a shortcut to lock your screen. You can click " Ctrl-A" and " NS"to lock the screen. This is convenient if you want to quickly lock the screen. Here is an example of displaying the screen lock after pressing the shortcuts.

Screen used by Pungki Arianto on mint. Password:

You can use your Linux password to unlock it.

Add password to lock screen

For security purposes, you can put a password on your screen session. You will be prompted for a password when you want to reattach screen. This password is different from the screen lock mechanism above.

To password protect your screen, you can edit the file “ $ HOME / .screenrc”. If the file does not exist, you can create it manually. The syntax would be like this.

Password crypt_password

To create " crypt_password", you can use the command" mkpasswd"on Linux. Here is a command with a password." pungki123".

[email protected]~ $ mkpasswd pungki123 l2BIBzvIeQNOs

mkpasswd will generate a password as shown above. Once you get the password, you can copy it to the file " .screenrc"and save. Now the file" .screenrc"will look like this.

Password l2BIBzvIeQNOs

Disable the screen the next time you start the screen, and you will be prompted for a password when you try to re-enable the screen, as shown below:

[email protected]~ $ screen -r 5741 Screen password:

Enter password " pungki123"and the screen will reconnect.

As soon as you run the screen password request and click " Ctrl-A" and " NS", then the output will be this.

Screen used by Pungki Arianto on mint. Password: Screen password:

You will need to enter a password twice... The first time is yours Linux password, the second is the password that you put in the file .screenrc.

Exiting screen

There are 2 (two) ways to exit the screen. First, we use " Ctrl-A" and " d"to turn it off. Second, we can use the screen blanking command. You can also use "Ctrl-A" and " TO"to nail the screen.