Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
linux_wiki:screen [2014/11/23 20:51] billdozor created |
linux_wiki:screen [2019/05/25 23:50] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
====== Screen ====== | ====== Screen ====== | ||
+ | |||
+ | **General Information** | ||
+ | |||
Screen is a " | Screen is a " | ||
This allows you to have multiple virtual terminal " | This allows you to have multiple virtual terminal " | ||
- | 1) Install if it is not already: | + | **Checklist** |
- | < | + | * Distro(s): Any |
+ | * Package: screen | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== Install and Start ===== | ||
+ | < | ||
yum install screen | yum install screen | ||
or | or | ||
Line 12: | Line 21: | ||
2) Start a screen session | 2) Start a screen session | ||
- | < | + | < |
- | screen | + | screen |
</ | </ | ||
Line 19: | Line 28: | ||
3) To view a list of all key bindings: | 3) To view a list of all key bindings: | ||
- | < | + | < |
Ctrl+a, then ? | Ctrl+a, then ? | ||
</ | </ | ||
Line 26: | Line 35: | ||
You only have to press " | You only have to press " | ||
Press Space ore Enter to leave the help screen. | Press Space ore Enter to leave the help screen. | ||
+ | |||
+ | ---- | ||
===== Some Examples ===== | ===== Some Examples ===== | ||
- | === Creating and Moving Between Screens === | + | ==== Creating and Moving Between Screens |
Start top in one screen, create a new screen, and cycle between the two. | Start top in one screen, create a new screen, and cycle between the two. | ||
Start top | Start top | ||
- | < | + | < |
top | top | ||
</ | </ | ||
Create a new screen | Create a new screen | ||
- | < | + | < |
Ctrl+a, then c | Ctrl+a, then c | ||
</ | </ | ||
You will be on the new screen session. Do something else to see the difference: | You will be on the new screen session. Do something else to see the difference: | ||
- | < | + | < |
free -m | free -m | ||
</ | </ | ||
Now, you can cycle between the two screen sessions by doing this: | Now, you can cycle between the two screen sessions by doing this: | ||
- | < | + | < |
Ctrl+a, then n | Ctrl+a, then n | ||
</ | </ | ||
Line 55: | Line 66: | ||
You will notice that top was never interrupted, | You will notice that top was never interrupted, | ||
- | === Detach and Reattach Screen === | + | ---- |
+ | |||
+ | ==== Detach and Reattach Screen | ||
The real power of screen is detaching a session and connecting back to it later. | The real power of screen is detaching a session and connecting back to it later. | ||
- | You can either intentionally | + | Detach scenarios: |
+ | * Intentionally | ||
+ | * Be working on a remote system and get a SSH/network interruption | ||
+ | |||
+ | In either scenario, you can reconnect to your still running screen session | ||
This can be demonstrated by executing a for loop that echos a number, sleeps for 1 second, and then keeps going. | This can be demonstrated by executing a for loop that echos a number, sleeps for 1 second, and then keeps going. | ||
1) If it is not open still, start screen | 1) If it is not open still, start screen | ||
- | < | + | < |
- | screen | + | screen |
</ | </ | ||
2) Start a long for loop...this should take about 5 minutes to complete. | 2) Start a long for loop...this should take about 5 minutes to complete. | ||
- | < | + | < |
for NUM in {1..300} | for NUM in {1..300} | ||
do echo -e " | do echo -e " | ||
Line 78: | Line 95: | ||
3) Detach from screen after it has started. | 3) Detach from screen after it has started. | ||
- | < | + | < |
Ctrl+a, then d | Ctrl+a, then d | ||
</ | </ | ||
4) List screen processes for your user. | 4) List screen processes for your user. | ||
- | < | + | < |
screen -ls | screen -ls | ||
</ | </ | ||
This will give you output similar to the following: | This will give you output similar to the following: | ||
- | < | + | < |
- | bill@dt-bill:~$ screen -ls | + | bill@dt-bill ~ $ screen -ls |
There is a screen on: | There is a screen on: | ||
- | 6732.pts-1.dt-bill (11/23/2014 07:28:40 PM) (Detached) | + | 19734.MySession (03/09/2015 11:13:38 PM) (Detached) |
1 Socket in / | 1 Socket in / | ||
- | bill@dt-bill: | + | ps -ef | grep 19734 |
- | bill | + | bill 19734 |
</ | </ | ||
You can see that the number is indeed a process ID. | You can see that the number is indeed a process ID. | ||
- | 5) Reattach to the screen: | + | 5) Reattach to the screen |
- | < | + | < |
- | screen -r 6732 | + | screen -r MySession |
+ | or | ||
+ | screen -r 19734 | ||
</ | </ | ||
- | Note: You only have to specify the screen PID if you have multiple screen sessions detached and you are connecting to a specific one. | + | Note: You only have to specify the screen PID if you have multiple screen sessions detached and you are connecting to a specific one. (If only 1 screen session, you can just type " |
You should find your still running for loop, chugging away. | You should find your still running for loop, chugging away. | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ==== Rename Existing Session ==== | ||
+ | |||
+ | If you started a new screen session without specifying a name or want to rename a session: | ||
+ | |||
+ | 1) Attach to your session | ||
+ | <code bash> | ||
+ | screen -r MySession | ||
+ | </ | ||
+ | |||
+ | 2) Command Key, then colon | ||
+ | <code bash> | ||
+ | Ctrl+A : | ||
+ | </ | ||
+ | |||
+ | 3) Type sessionname MyNewName, then enter | ||
+ | <code bash> | ||
+ | : | ||
+ | </ |