Linux screen command detailed

  

When using ssh remote connection linux server work, for example, need to compile some programs and then the network is unstable, the work will be dry, and the reconnection will repeat the work, this time Screen can come in handy.

Cultivate good habits and use screen!

1. Install screen

--------------------- ------------

yum install screen

----------------------- ---------

2.Run screen

------------------------- -------

screen

------------------------------ --

3. Usage

Ctrl+a Then press c to create a new screen session

Ctrl+a then press n to jump to the next screen session

Ctrl+a then press p to return to the previous screen session

Ctrl+a and press d to place the current screen session in the background.

Ctrl+a then press (uppercase S Separate a screen session, separate it and use Ctrl+a and then tab to jump between the separated screens.

screen -ls List all current screen sessions

screen -r process number before Ctrl+a and then press d to place the session in the background call back.

If there is a sudden disconnection in ssh, then after you log in again, screen -ls will find that the status of the screen is in the (Attached) state. At this point we use screen -d to force him into the background, and then use Screen -r The process number calls him back.

If screen -ls sees a dead session, you can kill him with the screen -wipe process number.

eg:

#screen -list can see the running screen instance

There is a screen on:

80338.ttyp3.chh ( Detached)

1 Socket in /tmp/screens/S-chh.

Back screen -r 80338

Exit completely: #exit

Screen provides Two main functions:

Run multiple terminal sessions in one terminal.

A started program is separated from the real terminal that runs it, so it can run in the background. The real terminal can be turned off, and it can be reattached later at

.

Short instance

Open screen:

# screen

In a screen session, we can open a long-running program (such as top). Detach this terminal, you can then

reattach this same terminal from other machines (eg via ssh).

# top

Now Ctrl-a Ctrl-d to detach. Reattach Terminal:

# screen -r

or better:

# screen -R -D

Attach now here. The specific meaning is: first try to restore the offline screen session. If an offline screen session is not found, a new

screen session is created for the user.

Screen Command (in screen)

All commands start with Ctrl-a.

Ctrl-a ? Help Summary for each function

Ctrl-a c Create a new window (terminal)

Ctrl-a Ctrl-n and Ctrl-a Ctrl -p switches to the next or previous window

Ctrl-a Ctrl-N N is a number from 0 to 9 to switch to the corresponding window

Ctrl-a " Navigable list of all running windows

Ctrl-a a Clear Ctrl-a

Ctrl-a Ctrl-d Disconnect all sessions, all tasks in the session run in the background

Ctrl-a x With the password lock screen screen terminal

When the program internal terminal is closed and you log out of the terminal, the screen session is terminated.

screen is really a favorite tool, in addition to bringing you a lot of convenience when managing remote sessions, today I also found a very useful feature, synchronous display of your screen to another Conversation. This is especially useful for dealing with others, allowing the other party to see your actions simultaneously, leaving a lot of explanations to describe the work.

Method:

a. Both parties log in to the system at the same time

b. The demo side runs:

screen -S yahunet

c. Viewer running:

screen -x yahunet

Copyright © Windows knowledge All Rights Reserved