Introduction
In the world of system management and development, working with multiple terminal sessions simultaneously is a daily need. GNU Screen is a tool that allows you to multiply a single physical terminal in several virtual windows, facilitating task management without losing the context. This article shows you from installation to the most useful tricks to make the most of Screen in any Linux distribution.
What is GNU Screen?
GNU Screen is a free and open-source multiplexer that belongs to the GNU project. Its main function is to create, manage and disconnect terminal sessions that continue to run in the background, even when you close the SSH client or the emulator window. Each session can contain multiple windows, each with its own shell, which allows to change between them with simple key combinations.
Installation in the most popular distributions
In most Linux distributions repositories, Screen is available as a pre-compiled package. In Debian or Ubuntu just run:
sudo apt updatesudo apt install screen
In Fedora, the command is:
sudo dnf install screen
In Arch Linux and its derivatives:
sudo pacman -S screen
After installation, you can check the version withscreen --version.
Start and exit from a session
To launch a new Screen session simply writes:
screen
This creates a default window and places you inside it. To disconnect the session without finishing the processes that are running, use the combinationCtrl + afollowed byd. The session is in the background and you can reconnect it later with:
screen -r
If you have several active sessions, you can list them withscreen -lsand then resume what you need by specifying your ID or name.
Create and navigate between windows
Within a Screen session you can open as many windows as you need. Each window acts as an independent terminal.
- Create a new window:Ctrl + a c
- Change to the following window:Ctrl + a n
- Change to the above window:Ctrl + a p
- Go directly to a window by number:Ctrl + a [0-9]
- See the list of windows:Ctrl + a w
Divide the screen in regions
Screen also allows to divide the current window into horizontal or vertical regions, useful to compare output from two commands side by side.
- Horizontal division:Ctrl + a S(capital)
- Vertical division:Ctrl + a |(pipe)
- Change the focus between regions:Ctrl + a Tab
- Remove the current region:Ctrl + a X
- Close all regions except the current one:Ctrl + a Q
Each region can contain an independent window, so you can have, for example, a log tail in the upper region and an editor in the lower region.
Safe disconnection and reconnection
One of the greatest advantages of Screen is the ability to disconnect a session and reconnect it without losing the state of the processes. This is particularly valuable when you work through SSH and the connection is interrupted. Just press.Ctrl + a dfor detach, and when you start the connection again, runscreen -rto take it back exactly where you left it.
If you want a session to continue running even after closing the local terminal, you can start Screen with the parameter-dmS nombreto create a session disconnected from boot, useful for boot scripts or background tasks.
Customization using .Screenrc
Screen's behavior can be adjusted by the configuration file~/.screenrc. Some common customizations include:
- Define a status bar that shows the window name, time and system load:
hardstatus alwayslastlinehardstatus string '% {= kG} [% {= YD}% H% {= G}] [% =% {= kw}%?% -Lw%?% {r} (% {W}% n*% f% t%? (% u)%?% {r})% {w}%?% + Lw%?% =% {g}] [% {= YD}% m /% d% {= C}% C% A] '
- Change the exhaust key combination ifCtrl + ainterferes with other applications:
escape
After editing.screenrc, recharge the configuration within an active session withCtrl + a :followed bysource ~/.screenrcor simply start a new session to make the changes effective.
Good practices and advice
- Name your sessions with
-S nombrewhen you start them to easily identify them later. - Use the activity register (Ctrl + a H) to create a log of everything that happens in the current window.
- Combine Screen with tmux or byobu if you need more advanced features, but remember that Screen is lighter and present in virtually any UNIX system.
- Avoid leaving critical processes in a disconnected session without supervision; regularly review the use of resources withCtrl + a *showing a CPU consumption report and window memory.
Conclusion
GNU Screen remains an essential tool for anyone who spends time on the Linux command line. Its ability to multiplexate terminals, disconnect and reconnect sessions, and customize the environment by simply using a configuration file makes it a powerful ally for managers, developers and advanced users. With the commands and tips presented in this article, you will be ready to make the most of Screen and improve your daily workflow in the terminal.


