Show pageOld revisionsBacklinksBack to top This page is read only. You can view the source, but not change it. Ask your administrator if you think this is wrong. ====== Screen ====== **General Information** Screen is a "full-screen window manager that multiplexes a physical terminal between several processes". (screen man page) This allows you to have multiple virtual terminal "workspaces" within 1 actual terminal session. **Checklist** * Distro(s): Any * Package: screen ---- ===== Install and Start ===== <code bash> yum install screen or apt-get install screen </code> 2) Start a screen session <code bash> screen -S MySession </code> 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 ? </code> The listed commands have multiple ways of being executed. You only have to press "Ctrl+a" and then the key letter for the desired action. 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 </code> Create a new screen <code bash> Ctrl+a, then c </code> You will be on the new screen session. Do something else to see the difference: <code bash> free -m </code> Now, you can cycle between the two screen sessions by doing this: <code bash> Ctrl+a, then n </code> You will notice that top was never interrupted, it was running the entire time on its screen session. ---- ==== 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 </code> 2) Start a long for loop...this should take about 5 minutes to complete. <code bash> for NUM in {1..300} do echo -e "Number is: ${NUM}" echo "Sleeping for 1 second..." sleep 1 done </code> 3) Detach from screen after it has started. <code bash> Ctrl+a, then d </code> 4) List screen processes for your user. <code bash> screen -ls </code> This will give you output similar to the following: <code bash> bill@dt-bill ~ $ screen -ls There is a screen on: 19734.MySession (03/09/2015 11:13:38 PM) (Detached) 1 Socket in /var/run/screen/S-bill. ps -ef | grep 19734 bill 19734 1 0 23:13 ? 00:00:00 SCREEN -S MySession </code> 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 </code> 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 "screen -r") 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 </code> 2) Command Key, then colon <code bash> Ctrl+A : </code> 3) Type sessionname MyNewName, then enter <code bash> :sessionname MyNewName </code> linux_wiki/screen.txt Last modified: 2019/05/25 23:50(external edit)