Powerful screen commands in Linux

Source: Internet
Author: User

Link: http://hi.baidu.com/tjuer/item/a3452480db2aa92b100ef38b

Today, we found a "baby", which is the Linux screen command. For remote logon, it not only provides nohup functions, it also provides my favorite "multiple desktops" feature.

Usually open a putty remote login, usually in twoProgramSwitch between them. What should I do? CTRL-Z, FG, BG? These are too troublesome. In fact, we can use the screen command to achieve easy and convenient switching.

I mainly refer to the following two articles:Article(Appended to the end), I will summarize the methods as follows:

"First use the screen [-S] command to create a session, and then you can create multiple windows in this session. You can use screen [-S] to create multiple sessions, and each session can create multiple windows. You can use ctrl-a n/P or other commands to switch between windows. To switch between multiple sessions, You Need To Ctrl-a d to log on to the session (like the root of a big tree), and then check which sessions are available through screen-ls, then, use screen-R to determine the session to be restored. For an attached session, you cannot directly screen-R. You need to screen-d before you can screen-R"

■ ■

[Reprinted 1]

System Administrators often need to log on to the server remotely.
Then run some programs on the server.
Sometimes
It takes a long time (more than 12 hours)
This is to exit the Remote Management Terminal if the program is not completed.
Remote programs may be replaced.
In the past, the common solution was to use the nohup command.
However, nohup has many problems.
When Screen
This is all done.
Run the screen command.
Creates a Single Window running shell.
Here
You can run the program you need
Then press Ctrl + a d to exit the newly created window (return to the environment before the screen)
Then, press screen to create a new terminal window.
That's it.
You can create multiple shell windows (these windows can run your own applications)
In this way, you exit the Remote Management window (entering the screen environment)
The windows between your screen Windows will not be closed.
The application running inside will naturally not be used.
Use screen-ls to view all screen sessions
You can use screen-r sessionid to enter a specific screen session specified by sessionid.
When the screen session is no longer used
Screen-r sessionid
Exit to exit

Unix/Linux tool: screen command
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
More ..
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 ( May contain multiple windows )
Thrown to the background for execution. When the screen session is detach by pressing C-a D, the system will return to the status before the screen is started, at this time, the process running in each window in the screen SESSION (both the foreground and 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 like to exit shell,You only need to enter the exit command, The following prompt will appear after exiting successfully
[Screen is terminating]

[Reprint 2]

Linux screen commands

Function Description:
When using telnet or SSH to remotely log on to Linux, if the connection is interrupted abnormally, the system will open a new session when the connection is reconnected, and the original session. Screen command cannot be restored to solve this problem. The screen tool is a terminal multi-path Adapter. In essence, this means that you can use a single terminal window to run multi-terminal applications.
Syntax:
Screen [-amrvx-ls-Wipe] [-D <job Name>] [-H <number of rows>] [-r <job Name>] [-S] [-S <job Name>]
Note:
Screen is a multi-window hypervisor. The so-called window refers to a full-screen text screen. The screen program is usually used only when you use Telnet to log on to the host or when you use an older terminal.
Parameters:
-A adjusted all windows to the current terminal size.
-D <job Name>: offline the specified screen job.
-H <number of rows> specifies the number of buffer rows in the window.
-M creates a new screen job even if the screen job is already in the job.
-R <job Name> restores an offline screen job.
-R first tries to restore the offline job. If an offline job cannot be found, a new screen job is created.
-S specifies the shell to be executed when a new window is created.
-S <job Name> specifies the name of the screen job.
-V displays the version information.
-X restores the offline screen job.
-Ls or -- List displays all current screen jobs.
-Wipe checks all current screen jobs and deletes unusable screen jobs.
Common screen parameters:
Screen-s yourname-> Create a session named yourname
Screen-ls-> list all current sessions
Screen-r yourname-> return to yourname session
Screen-D yourname-> remote detach a session
Screen-d-r yourname-> end the current session and return to yourname.
In each screen session, all commands start with Ctrl + a (c-.
C-? -> Help. Simple instructions are displayed.
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 0 .. 9-> switch to 0th .. 9 windows
CTRL + A [space]-> from the upper window 0 in sequence to the lower window 9
C-a c-a-> switch between the two recently used Windows
C-a X-> lock the current window and use the user password to unlock it.
C-a D-> detach: temporarily leaves the current session, throwing the current screen session (which may contain multiple windows) to the background for execution, and returning to the status when the screen is not yet in progress, at this time, the process running in each window in the screen SESSION (both the foreground and background) continues to be executed, even if logout is not affected.
C-a z-> put the current session in the background for execution, and use the shell FG command to go back.
C-a W-> Windows: list the Windows Enabled
C-a t-> time: displays the current time and the system load
C-a K-> Kill window, force close the current window

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.