Document directory
- (E) But how do I switch between these two tasks?
- Common screen commands
Linux screen command usage
From: http://www.9usb.net/201002/linux-screen-mingling.html
As a linux server administrator, it is often necessary to log on to a remote linux machine using ssh for some time-consuming operations.
You may have used telnet or SSH to remotely log on to linux and run some programs. If these programs need to run for a long time (several hours) and a network fault or client fault occurs during the running of the program, the connection between the client and the remote server will be the terminal, in addition, commands that do not end normally on the remote server will be terminated.
For example, after you SSH to the host, start batch scp commands. If the ssh thread is disconnected, the scp process will be interrupted. Some time-consuming jobs are running on the remote server, but the work is about to get off work. If you quit, the operation will be interrupted. How can this problem be solved?
We can use the screen command to solve this problem. To continue executing the program on the server when SSH is disconnected.
So what is the screen command?
Screen is called a full Screen window manager, which can be used to easily obtain the effects of multiple virtual terminals on a physical terminal.
Screen function description:
To put it simply, Screen is a window manager that allows multiple processes to reuse one physical terminal. This means that you can use a single terminal window to run multiple terminal applications. Screen has the concept of session. You can create multiple screen Windows in one screen session, just like operating a real telnet/SSH connection window in each screen window.
Screen command syntax:
Screen [-AmRvx-ls-wipe] [-d <job Name>] [-h <number of rows>] [-r <job Name>] [-s] [-S <job Name>]
Screen command parameters:
-A-[r | R]: adjust all windows to the current terminal size.
-C filename: Replace the specified filename file with the screen configuration file '. screenrc '.
-D [pid. tty. host]: disconnect the screen process (when using this command, the screen status must be Attached, that is, the user can connect to the screen ). Generally, the process name is expressed in the form of pid. tty. host (the status can be seen through the screen-list command ).
-D [pid. tty. host] implements the same functions as the-d command. The difference is that if the execution is successful, the user in the screen will be kicked off and logout will be made.
-H <number of rows> specifies the number of buffer rows in the window.
-Ls or-list displays all current screen jobs.
-M creates a new screen job even if the screen job is already in the job.
-P number or name: select a window in advance.
-R [pid. tty. host] restores the offline screen process. If there are multiple disconnected processes, you must specify [pid. tty. host]
-R first tries to restore the offline job. If an offline job cannot be found, a new screen job is created.
-S shell specifies the shell to be executed when a new window is created.
-S <job Name> specifies the name of the screen job. (Used to replace the [pid. tty. host] naming method, which can simplify the operation ).
-V displays the version information.
-Wipe checks all current screen jobs and deletes unusable screen jobs.
-X restores the offline screen job.
General Usage of the Screen command:
Screen-d-r: connect to a screen process. If the process is attached, kill the remote user and connect again.
Screen-D-r: connect to a screen process. If the process is attached, kill the remote user and ask him to log out Before connecting.
Screen-ls or-list: displays existing screen processes, common commands
Screen-m: If you are in a Screen process, use the shortcut key crtl + a c or directly press screen to create a new window. screen-m can create a screen process.
Screen-dm: Creates a new screen and uses the detached mode by default, that is, the screen will not be connected after the screen is created.
Screen-p number or name: select a window in advance.
Simple Steps to run a program in the background using Screen:
1> to perform an operation, run the following command to create a Screen:
[Linux @ user ~] $ Screen-S test1
2> then you can perform operations in it. If your task is not completed, you must go away and use the command to keep Screen:
[Linux @ user ~] $ Ctrl + a + d # press Ctrl + a, and then press d to keep the Screen
[Detached] # This prompt is displayed, indicating that the Screen has been retained.
If your work is complete, enter:
[Linux @ user ~] $ Exit # This indicates that the exit is successful.
[Screen is terminating]
3> if you have retained Screen for the last time, run the following command to view it:
[Linux @ user ~] $ Screen-ls
There is a screen on:
9649. test1 (Detached)
Run the following command to restore the Screen:
[Linux @ user ~] $ Screen-r test1 (or 9649)
Shortcut Keys used in the Screen command
Ctrl + a c: create a window
Ctrl + a w: Window list
Ctrl + a n: Next window
Ctrl + a p: previous window
Ctrl + a 0-9: switch between 0th windows and 9th windows
CTRL + a k (uppercase): Close the current window and switch to the next window (when the last window is exited, the terminal is automatically terminated and returned to the original shell state)
Exit: Close the current window and switch to the next window. (when you exit the last window, the terminal stops automatically and returns to the original shell state)
CTRL + a d: exit the current terminal and return the shell command status before loading the screen.
Refer:
Http://www.cyberciti.biz/tips/linux-screen-command-howto.html
How do I Use Multiple Screens on One Terminal over ssh session?
By nixcraft on
December 7, 2005· 22 comments ·
Last updated January 24,200 9
In centos,
Debian Linux,
Gentoo Linux
Most of the time GUI is not available on remote Linux system, you login over SSH and start to work, if you need to run two or three task at a time, you login over SSH two or three times. however, with screen Windows Manager Utility you can run multiple terminals
At the same time from single console login over ssh session (UNIX guru uses the term called multiplexing for this concept). Any seasoned Linux Admin shocould be aware of this nifty Tool
Install screen if it is not installed under Debian Linux
Type the following command:
# apt-get install screen
FreeBSD user can use ports to install screen
# cd /usr/ports/misc/screen
# make install clean
Login to remote server over ssh
$ ssh me@myserver.com
(C) Start Screen session. you can name your window/session (1 is name of session ):
$ screen -S 1
Let us start pine Mail reader on first session or window.
$ pine
(D) Next you wowould like to download something from ftp/HTTP site while you are reading emails. you need to create another screen window by pressing special key combination. press Ctrl + A followed by C key (first hit Ctrl + A, releases both keys and press
C). As soon as you hit 'C' you will get new shell prompt at console. Now use wget to download belenix.iso.bz2 (Solaris live CD) from net:
$ wget http://www.genunix.org/distributions/belenix_site/binfiles/belenix.iso.bz2
(E) But how do I switch between these two tasks?
- Switching between windows is the specialty of screen utility. so to switch between pine and wget window (or session) press CTRL + a followed by n key (first hit CTRL + a, releases both keys and press n ).
- To list all windows use the command CTRL + a followed by "key (first hit CTRL + a, releases both keys and press ").
- To switch to window by number use the command CTRL + a followed by '(first hit CTRL + a, releases both keys and press 'it will prompt for window number ).
Common screen commands
| Screen command |
Task |
| Ctrl + a c |
Create new window |
| Ctrl + a k |
Kill the current window/session |
| Ctrl + a w |
List all windows |
| Ctrl + a 0-9 |
Go to a window numbered 0 9, use Ctrl + a w to see number |
| Ctrl + |
Toggle/switch between the current and previous window |
| CTRL + A S |
Split terminal horizontally into regions and press Ctrl + a c to create new window there |
| CTRL + A: resize |
Resize Region |
| CTRL + A: Fit |
Fit screen size to new terminal size. You can also hitCTRL + A FFor the same task |
| CTRL + A: Remove |
Remove/delete region. You can also hitCTRL + A xFor the same taks |
| CTRL + a tab |
Move to next Region |
| CTRL + a d (shift-d) |
Power detach and logout |
| CTRL + A D |
Detach but keep shell window open |
| CTRL-A Ctrl -\ |
Quit Screen |
| CTRL-? |
Display help screen I. e. display a list of commands |
Suggested readings:
See screen command man page for further details:
man screen