filmov
tv
GNU Screen Basic Tutorial

Показать описание
Today we are taking a look at GNU Screen. Technically defined as a terminal multiplexer, Screen can be used to run several login sessions from a single terminal, which is useful when running long tasks on remote servers and for other situations. In just a few minutes of this video you will learn all you need to know to start using Screen. The application itself is available in most Linux distros, but may not be installed by default.
To illustrate our use case, let's create a simple Bash script, which will continuously output a line of text, pausing for a second each time. We can see that it's working, but unfortunately we cannot do anything else with this terminal until our long running task is complete. This is where Screen comes in. After we start it, the program version and various information is displayed and we can press Space or Enter to put us into a Bash environment running inside Screen. We start our script, and once it's running we can press 'Ctrl+a' and 'd' to detach from the session. If we check running processes, our script is indeed still running in the background. We can now issue the 'screen -r' command to return to our active session and watch the progress. Let's stop the script and issue the 'exit' command to terminate the Screen session. As you would expect, we are no longer able to attach to any running Screen session.
When creating sessions, it's useful to provide them with names, in order to easily distinguish them later. We do that by running screen with the '-S' flag and supplying our desired name. Let's run our script and detach from the session with 'Ctrl+a' and 'd'. If we now run 'screen -ls', we can see our newly created session with its assigned name. Let's create another session and run our script there as well. If we detach and run 'screen -ls' again, we see both our sessions listed and both instances of the script are indeed still running in the background. We can now reattach to any of our sessions by supplying either the session PID number, or its name. Let's stop this script and terminate the session. As expected, 'screen -ls' only shows the remaining Screen session.
Another useful feature of Screen is virtual "windows", allowing us to run multiple things in a single Screen session and even have them side by side. Pressing 'Ctrl+a' and 'S' splits our screen horizontally. Vertical splitting is done with 'Ctrl+a' and 'V', but may not work, depending on your GNU Screen version. We can switch between split screen regions by pressing 'Ctrl+a' and 'Tab', but nothing is running in the second half, because at the moment it's only a graphical separation, not a new session. We need to create a virtual window inside the bottom section, and we do that by pressing 'Ctrl+a' and 'c'. This creates another session, inside our single Screen session. This sounds confusing, hence the naming distinction between a Screen session and "windows" inside that session. Let's detach from the entire Screen by pressing 'Ctrl+a' and 'd'. Reattaching back, you may think that one of our "windows" has been lost, but only the split screen representation of them has. By pressing 'Ctrl+a' and '"' we can see the list of all active "windows" inside our session and we can easily switch between them.
There are many features to GNU Screen, what you have learned in the last few minutes should be sufficient for most needs.
To illustrate our use case, let's create a simple Bash script, which will continuously output a line of text, pausing for a second each time. We can see that it's working, but unfortunately we cannot do anything else with this terminal until our long running task is complete. This is where Screen comes in. After we start it, the program version and various information is displayed and we can press Space or Enter to put us into a Bash environment running inside Screen. We start our script, and once it's running we can press 'Ctrl+a' and 'd' to detach from the session. If we check running processes, our script is indeed still running in the background. We can now issue the 'screen -r' command to return to our active session and watch the progress. Let's stop the script and issue the 'exit' command to terminate the Screen session. As you would expect, we are no longer able to attach to any running Screen session.
When creating sessions, it's useful to provide them with names, in order to easily distinguish them later. We do that by running screen with the '-S' flag and supplying our desired name. Let's run our script and detach from the session with 'Ctrl+a' and 'd'. If we now run 'screen -ls', we can see our newly created session with its assigned name. Let's create another session and run our script there as well. If we detach and run 'screen -ls' again, we see both our sessions listed and both instances of the script are indeed still running in the background. We can now reattach to any of our sessions by supplying either the session PID number, or its name. Let's stop this script and terminate the session. As expected, 'screen -ls' only shows the remaining Screen session.
Another useful feature of Screen is virtual "windows", allowing us to run multiple things in a single Screen session and even have them side by side. Pressing 'Ctrl+a' and 'S' splits our screen horizontally. Vertical splitting is done with 'Ctrl+a' and 'V', but may not work, depending on your GNU Screen version. We can switch between split screen regions by pressing 'Ctrl+a' and 'Tab', but nothing is running in the second half, because at the moment it's only a graphical separation, not a new session. We need to create a virtual window inside the bottom section, and we do that by pressing 'Ctrl+a' and 'c'. This creates another session, inside our single Screen session. This sounds confusing, hence the naming distinction between a Screen session and "windows" inside that session. Let's detach from the entire Screen by pressing 'Ctrl+a' and 'd'. Reattaching back, you may think that one of our "windows" has been lost, but only the split screen representation of them has. By pressing 'Ctrl+a' and '"' we can see the list of all active "windows" inside our session and we can easily switch between them.
There are many features to GNU Screen, what you have learned in the last few minutes should be sufficient for most needs.
Комментарии