Differences
This shows you the differences between two versions of the page.
linux_wiki:screen [2016/03/18 23:23] billdozor [Screen] |
linux_wiki:screen [2019/05/25 23:50] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Screen ====== | ||
- | **General Information** | ||
- | |||
- | Screen is a " | ||
- | |||
- | This allows you to have multiple virtual terminal " | ||
- | |||
- | **Checklist** | ||
- | * Distro(s): Any | ||
- | * Package: screen | ||
- | |||
- | ---- | ||
- | |||
- | ===== Install and Start ===== | ||
- | <code bash> | ||
- | yum install screen | ||
- | or | ||
- | apt-get install screen | ||
- | </ | ||
- | |||
- | 2) Start a screen session | ||
- | <code bash> | ||
- | screen -S MySession | ||
- | </ | ||
- | |||
- | Screen may or may not show some startup dialog, but once you are past that, it will look just like a normal terminal prompt. | ||
- | |||
- | 3) To view a list of all key bindings: | ||
- | <code bash> | ||
- | Ctrl+a, then ? | ||
- | </ | ||
- | |||
- | The listed commands have multiple ways of being executed. | ||
- | You only have to press " | ||
- | Press Space ore Enter to leave the help screen. | ||
- | |||
- | ---- | ||
- | |||
- | ===== Some Examples ===== | ||
- | |||
- | ==== Creating and Moving Between Screens ==== | ||
- | |||
- | Start top in one screen, create a new screen, and cycle between the two. | ||
- | |||
- | Start top | ||
- | <code bash> | ||
- | top | ||
- | </ | ||
- | |||
- | Create a new screen | ||
- | <code bash> | ||
- | Ctrl+a, then c | ||
- | </ | ||
- | |||
- | You will be on the new screen session. Do something else to see the difference: | ||
- | <code bash> | ||
- | free -m | ||
- | </ | ||
- | |||
- | Now, you can cycle between the two screen sessions by doing this: | ||
- | <code bash> | ||
- | Ctrl+a, then n | ||
- | </ | ||
- | |||
- | You will notice that top was never interrupted, | ||
- | |||
- | ---- | ||
- | |||
- | ==== Detach and Reattach Screen ==== | ||
- | |||
- | The real power of screen is detaching a session and connecting back to it later. | ||
- | |||
- | Detach scenarios: | ||
- | * Intentionally detach screen | ||
- | * Be working on a remote system and get a SSH/network interruption | ||
- | |||
- | In either scenario, you can reconnect to your still running screen session without loosing any work. Perfect for long running processes or scripts. | ||
- | |||
- | 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 | ||
- | <code bash> | ||
- | screen -s MySession | ||
- | </ | ||
- | |||
- | 2) Start a long for loop...this should take about 5 minutes to complete. | ||
- | <code bash> | ||
- | for NUM in {1..300} | ||
- | do echo -e " | ||
- | echo " | ||
- | sleep 1 | ||
- | done | ||
- | </ | ||
- | |||
- | 3) Detach from screen after it has started. | ||
- | <code bash> | ||
- | Ctrl+a, then d | ||
- | </ | ||
- | |||
- | 4) List screen processes for your user. | ||
- | <code bash> | ||
- | screen -ls | ||
- | </ | ||
- | |||
- | This will give you output similar to the following: | ||
- | <code bash> | ||
- | bill@dt-bill ~ $ screen -ls | ||
- | There is a screen on: | ||
- | 19734.MySession (03/ | ||
- | 1 Socket in / | ||
- | |||
- | ps -ef | grep 19734 | ||
- | bill | ||
- | </ | ||
- | |||
- | You can see that the number is indeed a process ID. | ||
- | |||
- | 5) Reattach to the screen using the session name or process id: | ||
- | <code bash> | ||
- | 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. (If only 1 screen session, you can just type " | ||
- | |||
- | 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> | ||
- | : | ||
- | </ |