How to Install and Use Screen on Linux (15 Practical Examples)

Linux TLDR
Last Updated:
Reading time: 4 minutes

Screen was a popular Linux command-line tool back in the day for launching and managing multiple shell sessions or splitting the screen vertically or horizontally across multiple terminal instances within a single terminal window manager.

This way, you are allowed to manage multiple shell sessions within a single SSH session, run a program in the background, maximize workspace efficiency, monitor various command statuses on one screen, and more.

However, later it was replaced with better tools such as Tmux or Zellij, and now there are many advanced terminal emulators available that provide built-in multiplexers that require zero learning curves, such as Tilix, Wave, Wrap, etc.

If you seek my advice and you’re a beginner stumbling upon this article without knowledge of Screen or Tmux, I recommend learning to use Tmux instead of Screen. And if you’re already familiar with Tmux and other tools, you can learn to use Screen for fun.

In this tutorial, I’ll show you how to install a screen on Linux and then how to use it with different examples.

Tutorial Details

DescriptionScreen
Difficulty LevelLow
Root or Sudo PrivilegesNo
OS CompatibilityUbuntu, Manjaro, Fedora, etc.
Prerequisites–
Internet RequiredYes (for installation)

How to Install Screen on Linux

On certain Linux distributions, screen comes preinstalled, and to verify, you can run the β€œscreen” command. However, if you encounter the β€œscreen: command not found” error, use one of the following commands, depending on your Linux distribution, to install screen.

# On Debian, Ubuntu, Mint, Pop!_OS, etc.
$ sudo apt install screen

# On RHEL, CentOS, Fedora, Rocky Linux, AlmaLinux, etc.
$ sudo yum install screen

# On Gentoo Linux
$ sudo emerge -a sys-apps/screen

# On Alpine Linux
$ sudo apk add screen

# On Arch Linux
$ sudo pacman -S screen

# On OpenSUSE
$ sudo zypper install screen

Once the installation is complete, the β€œscreen” command becomes accessible.

Usage of Screen

The screen command takes three arguments: the first is the option, the second is the command, and the third is the arguments (all of which are optional).

$ screen [options] [command [arguments]]

Now, let’s see some practical examples on the usage of the β€œscreen” command.

1. To start a screen session, simply enter the β€œscreen” command without any options; it will present an interface identical to the command prompt.

πŸ“
On the first launch, you will encounter the following welcome screen, which you can skip by pressing the β€œSpace” key twice.
screen interface

2. Once you’re on the screen, you can start creating multiple windows or splitting screens, but all of this requires knowing the correct key combinations. In this article, I’ll show you most of it, but if you ever forget them, you can press β€œCtrl+a” and then β€œ?” to open the screen key bindings page.

screen key bindings screen

3. As of now, you’re operating within a single window, but you can open multiple windows within a single-screen session by using β€œCtrl+a” and then β€œcβ€œ. This is particularly handy when you’ve initiated a single SSH session that’s already occupied and need to open a new window without reinitializing the SSH session.

πŸ“
Relax while viewing the blank screen below; unlike Tmux, Screen doesn’t display any visual changes when creating a new window.
creating a new window in screen

4. When you create a new window in an existing screen session, there’s no visual change, causing confusion in identifying the current working window. To address this, you can use β€œCtrl+a” and then β€œ"” (double quote) to list all created windows, with the active one highlighted.

listing all screen windows

5. To navigate between different windows, you can use either arrow keys or β€œj” and β€œk” while listing all windows using the previous method, or use β€œCtrl+a” with β€œn” (to move forward) and β€œp” (to move backward) within the active window.

6. By default, the names of the window titles are set to the program that created them (often bash), but to distinguish each window, you can rename them. First, enter to desired window, then use β€œCtrl+a” followed by β€œShift+aβ€œ, it will open a prompt titled β€œSet Window's title to: <title>β€œ. Provide your desired title and press enter to save.

naming window title in screen

Once you rename the window title, you’ll find a new title that will make it more distinguishable when you list all the windows.

list all window with new title

7. To terminate an active window session, use β€œCtrl+a” followed by β€œkβ€œ; it will ask for confirmation, where you should press β€œY” for yes.

terminating window

8. You can split the screen horizontally by using β€œCtrl+a” and then β€œShift+sβ€œ; to jump between them, use β€œCtrl+a” and then β€œTabβ€œ; lastly, to close the active window, use β€œCtrl+a” and then β€œShift+xβ€œ.

split screen horizontally

9. To split the screen vertically, use β€œCtrl+a” and then β€œShift+|β€œ; to jump between them, use β€œCtrl+a” and then β€œTabβ€œ; lastly, to close the active window, use β€œCtrl+a” and then β€œShift+xβ€œ.

split screen vertically

10. To detach the screen session, you can use β€œCtrl+a” and then β€œdβ€œ; this way, you can avoid terminating all the running programs inside the screen.

detach screen session

11. To list all detached screen sessions, use the β€œscreen -ls” command; furthermore, you can list all the running processes on your system and filter the output to display only those with the β€œSCREEN” command.

listing the detached screen session

12. To reattach the screen session either you can use the β€œscreen -r <process-id>” command or just execute the β€œscreen -r” command to reattach the most recently detached screen session.

13. If you’ve accidentally detached multiple screen sessions and now want to terminate them, the first method is to reattach them and use the β€œexit” command to quit, or alternatively, you can use the following command to terminate all detached screen sessions at once.

$ screen -ls | grep Detached | cut -d. -f1 | awk '{print $1}' | xargs kill

Output:

killing all deattached screen sessions

14. The screen allows locking the current session with the user login password, so to lock it, use β€œCtrl+a” and then β€œxβ€œ; this will show the following prompt for the user login password to unlock.

⚠️
If someone has access to your system, they can find the screen process ID and, in a new terminal window, reattach to the locked screen session to access everything. Therefore, it’s not advisable to depend on this locking mechanism when handling crucial tasks.
locking screen session

15. The screen has a built-in mechanism to log every action during the session recording, eliminating the need to log each executed command individually and making it useful in debugging. To start screen logging, simply use β€œCtrl+a” and then β€œShift+hβ€œ, which will also display the log file location at the bottom.

enable screen logging

When you quit the screen session or stop the screen logging by using the same β€œCtrl+a” and then β€œShift+n” key combination, it will stop recording and append all the changes to the file displayed during the start of recording. To view the log, you can simply use the β€œcat” or β€œbat” commands.

Final Word

Today, most users might not use the screen, but it was once a great tool. Now, if you have any questions or queries related to the article, you can ask them in the comment section.

Till then, peace!

Join The Conversation

Users are always welcome to leave comments about the articles, whether they are questions, comments, constructive criticism, old information, or notices of typos. Please keep in mind that all comments are moderated according to our comment policy.