[Reprint] Unix/Linux tool: screen command usage

Source: Internet
Author: User
Recently, my colleague introduced me to the screen command, which is really good. In the past, in order to let the program run without the terminal, either let it run in the background or use nohup to run, but if the program needs to interact, it will be troublesome. For example, you need to use SCP for copy, enter a password, and the data volume is large. It takes a long time. People who have met will know the pain.

With screen, everything is simple. Here I will post an article about it, which is very convenient to use.

Screen your screen
Text: Lin Sijing
Email: becks.lin@ec-base.com

Preface
What is screen?

According to man, screen is a multi-functional full-screen window manager. Each virtual terminal can provide you with the DEC VT100 Terminal function,
You may ask: Dec VT100
What is terminal? If you have logged on to the BBS of some character interfaces, you may remember that when you register, you are required to enter your terminal type, and the general preset is the Dec
VT100 termina. In addition, screen also provides so 6429 (ECMA 48, ANSI x3.64) and ISO
2022 standards operation function.

What can screen do?
If in the past, maybe screen was a good companion for you to log on to the BBS site, but now everyone is directly logged on to the GUI, that is, BBS on the Web interface. when you are logging on to multiple BBS and do not want to switch between multiple windows. then screen can help you.

Of course, screen is not designed for BBS,
It allows you to simply open a terminal window to handle a lot of (process) tasks. For example, you are writing a program on shell, it happens that you need to restart a service and
FTP uploads a large file. At this time, you can call screen. You only need to press three keys to switch between the three windows without having to use the mouse. or you can log on to the service using tools such as putty.
You do not want to shut down the current process when you exit. For example, if you are copying a file, you can use screen to make the foreground process of file copying enjoy the "treatment" of the background process ".

It is precisely because of the various practical functions of screen that it has become an essential tool for many * UNIX players, making * UNIX's daily operation management more convenient.

Screen usage
It is easy to use screen. You only need to type screen in shell to open a screen session.
In each screen session, all commands start with Ctrl + a (c-.

Now let me briefly introduce the basic commands

C-a c-> Create to open a new window
C-a n-> next, switch to the next window
C-a p-> previous, the previous window
C-a c-a-> Other, switch between two windows
C-a W-> Windows: list the Windows Enabled
C-a 0-> switch to 0th windows
C-A 1 .. 9-> switch to 1st .. 9 windows

C-a A-> Issue C-A, which can be moved to the beginning of a row in Emacs, VE, Bash, and tcsh.

C-a t-> time: displays the current time and the system load
C-a k (uppercase)-> Kill window, force close the current window

C-A [-> enter copy mode. In copy mode, you can roll back, search,
Copying is like using vi.

C-B backward, Pageup
C-F forward, Pagedown
H (uppercase) high: move the cursor to the upper left corner
L low: move the cursor to the lower left corner.
0 move to the beginning of the row
$ End of line
W forward one word, in the unit of words forward
B backward one word, move backward in the unit of words
Space is the start point of the marked area for the first time, and space is the end point for the second time
ESC end copy mode
C-A]-> paste, paste the content just selected in copy mode

C-? -> Help. Simple instructions are displayed.

C-a D-> detach, convert the current screen session (May contain multiple Windows)
Drop to the background for execution. When the screen session is detach by pressing C-a D, the status will return to the status before the screen is started.
The process running in each window in the screen SESSION (either the foreground or the background) continues to be executed, even if logout is not affected.

When login comes in next time:

Screen-ls-> display all screen sessions
Screen-R [keyword]-> select a screen session to resume the dialog.

If the screen-ls contains attached sessions:
Screen-d [keyword]-> force detach to "take over"

Instance
I have read so much about the description. Let's end our learning today with an actual example.

After enabling a screen, run Ctrl + a d to edit a file with Joe:

[Becks @ EC-base Becks] $ Screen
[Detached]

At this time, when we run PS-E, we can see that PTS/2, the screen I just run is running Joe.
6264 pts/2 00:00:00 bash
6354 pts/2 00:00:00 Joe

When we want to resume this session, we only need to type screen-R. When you have multiple sessions, the system will prompt you to select one, as shown below:
[Becks @ EC-base Becks] $ screen-R
There are several suitable screens on:
6263. pts-1.ec-base (detached)
6382. pts-1.ec-base (detached)
Type "screen [-D]-R [pid.] TTY. Host" to resume one of them.

Enter the PID of the session to restore
[Becks @ Becks] $ screen-r 6263

To exit the screen session, just type the exit command, just like to exit shell. After the screen session is successfully exited, the following prompt will be displayed:
[Screen is terminating]

The simple usage of screen is introduced here. For more functions and features, refer to man.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.