If you have ever experienced the frustration of losing your work due to a dropped connection while performing a lengthy task on a remote machine via SSH, then you are not alone. Fortunately, there is a solution to this common problem: the screen utility. With the screen, you can easily resume your sessions and avoid losing your valuable work. Learn how to use screen and prevent interruptions from ruining your productivity.
What is screen?
Screen, also known as GNU Screen is a terminal multiplexer. With Screen, you can easily start a session and open multiple virtual terminals, or windows, within that session. The best part of the screen is that your processes will keep running even if you get disconnected or switch to a different window. Try Screen for a seamless and uninterrupted terminal experience.
How to Check Installed GNU Screen on Linux
Nowadays, the GNU screen is installed by default on most Linux distros. To check if it’s installed on your Linux system or not simply type the following command:
screen --version
Output
Screen version 4.06.02 (GNU) 23-Oct-17
If you don’t find screen installed on your system, you can easily install screen by using the package manager of your distro.
How to Install Linux Screen on Ubuntu and Debian
Use sudo
command on Ubuntu or Debian to install the Linux screen. Use the following command:
sudo apt update
sudo apt install screen
How to Install Linux Screen on CentOS and Fedora
Again with sudo command, you can easily install Linux screen on CentOS and Fedora. Use the following command:
sudo yum install screen
How to start Linux Screen
By simply typing screen
in your console and hit enter. This will initiate a screen session, which will generate a fresh window and launch a shell within that window.
screen
Once you’ve got your screen session up and running, you’ll want to familiarize yourself with the various commands available. To access the list of all commands type: Ctrl+a ?
How to Start Named Session on Screen
If you run multiple screen sessions, named sessions can be quite handy. You can create a named session by executing the screen command with the argument:
screen -S session_name
Make sure to pick a descriptive session name to keep things organized. This can be especially useful for search and discovery purposes.
How to Work with Linux Screen Windows
Starting a new Linux screen session creates a single window containing a shell. With Screen, you can create multiple windows within the same session.
To create a new window with a shell, simply type Ctrl+a c. The first available number from the range 0 to 9 will be assigned to the new window.
Here are some most common commands for Linux Screen Windows:
Ctrl+a
c
Create a new window with a shell.Ctrl+a
List all windows.Ctrl+a
0
Switch to window 0 by number.Ctrl+a
A
Rename the current window.Ctrl+a
S
Split the current region horizontally into two regions.Ctrl+a
|
Split the current region vertically into two regions.Ctrl+a
tab
Switch the input focus to the next region.Ctrl+a
Ctrl+a
Toggle between the current and previous windowsCtrl+a
Q
Close all regions but the current one.Ctrl+a
X
Close the current region.
How to Detach from Linux Screen Session
To detach from the scene session simply type Ctrl+a d
and the program running in the screen session will continue to run after you detach from the session.
How to Reattach to a Linux Screen
After detaching from the Linux screen session if you want to reattach and resume your screen session simply use the command below:
screen -r
If you have multiple screen sessions running on your system, you need to append the scene session ID after the r
switch and you can resume the screen session with the given ID.
To find the session ID list with the currently running sessions follow the below command:
screen -ls
Output
There are screens on:
10835.pts-0.trioguide-desktop (Detached)
10366.pts-0.trioguide-desktop (Detached)
2 Sockets in /run/screens/S-trioguide.
After listing all the screen sessions, you can use the session ID to reattach the screen. From the above output if you want to restore the screen 10835.pts-0
then use the following command to restore the screen:
screen -r 10835
Choose the ID and append with -r
and restore the specific screen session.
How to customize Linux screen
When Screen is launched, it automatically reads its configuration parameters from /etc/screenrc
and ~/.screenrc
if the file is available. By modifying the default Screen settings with the .screenrc file, users can customize their preferences to enhance their experience. Check out this sample ~/.screenrc
configuration with a personalized status line and a variety of extra options.
~/.screenrc
# Turn off the welcome message
startup_message off
# Disable visual bell
vbell off
# Set scrollback buffer to 10000
defscrollback 10000
# Customize the status line
hardstatus alwayslastline
hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{= kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B} %m-%d %{W}%c %{g}]'
Basics of Linux Screen
To begin using the screen, follow these fundamental steps:
- Open the command prompt and type
screen
to start a new session. - Run the desired program within the screen session.
- To detach from the session, press
Ctrl-a
followed byCtrl-d
. - To resume the screen session, enter
screen -r
in the command prompt.
These simple steps will allow you to easily manage multiple terminal sessions and enhance your workflow. Don’t forget to utilize the powerful features of the screen to increase your productivity.
Conclusion
In this comprehensive tutorial, you have discovered how to efficiently use Gnu Screen. With the Screen utility, you can easily create multiple screen windows from a single session, switch between windows seamlessly, detach and resume screen sessions, and customize your screen terminal using the .screenrc file. Elevate your productivity with Gnu Screen.
For more in-depth insights, check out the Screen User’s Manual page.
If you still have questions regarding this tutorial, feel free to comment down below.