Guide to Linux screen Command

When working on a Linux terminal, you may sometimes need to keep several processes running at the same time. However, if you close the terminal or accidentally disconnect from a remote session, processes will terminate, and you may lose all your progress. This is where the Linux screen command comes in handy.

Screen is a powerful command-line utility that allows you to create and manage multiple terminal sessions within a single shell window or over SSH connections. It is a handy tool for managing long-running processes or multiple commands, even if you are not physically connected to the server.

Installing Screen

Most modern Linux distributions come with screen pre-installed. However, if it is not already installed on your system, you can install it using the package manager for your distribution. For instance, on Ubuntu, you can install it with the following command

sudo apt-get install screen

After installation, you can start using the screen command.

Creating a New Screen Session

To create a new screen session, simply type the following command

screen

This will start a new shell session within a screen session. You can also create a named session for easier identification

screen -S session_name

Screen Session Workflow Create Session Run Processes Detach Re-attach

Essential Screen Commands

Detaching and Re-attaching

To detach from a screen session, press Ctrl+A followed by d. This detaches the session and returns you to the shell prompt while all processes continue running in the background.

To re-attach to a screen session

screen -r

For multiple sessions, specify the session ID or name

screen -r session_name

Managing Screen Sessions

To list all active screen sessions

screen -ls
There are screens on:
   1168.pts-0.server    (Detached)
   1323.myproject       (Detached)
   1343.backup          (Attached)
3 Sockets in /run/screen/S-ubuntu.

To kill a specific screen session

screen -X -S session_name quit

Window Management

Command Action
Ctrl+A, c Create new window
Ctrl+A, n Switch to next window
Ctrl+A, p Switch to previous window
Ctrl+A, 0-9 Switch to window number
Ctrl+A, w List all windows
Ctrl+A, k Kill current window

Screen Splitting

Screen allows you to split the terminal window into multiple regions for multitasking

Command Action
Ctrl+A, S Split horizontally
Ctrl+A, | Split vertically
Ctrl+A, Tab Switch between regions
Ctrl+A, X Close current region
Ctrl+A, Q Close all regions except current

Copy and Paste

To copy and paste text within screen

  • Ctrl+A, [ Enter copy mode

  • Spacebar Start selection

  • Enter Copy selected text

  • Ctrl+A, ] Paste copied text

Advanced Features

Configuration File

You can create a .screenrc configuration file in your home directory to customize screen behavior

# Sample .screenrc
startup_message off
hardstatus alwayslastline "%{= kG}[%{G}%H%{g}][%= %{= kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B} %m-%d %{W}%c %{g}]"
defscrollback 10000

Monitoring Activity

To monitor activity in other windows

Ctrl+A, M    # Monitor activity in current window
Ctrl+A, _    # Monitor silence (30 seconds default)

Common Use Cases

  • Long-running processes Keep builds, backups, or downloads running after disconnecting

  • Remote server management Maintain persistent SSH sessions

  • Development workflow Run multiple terminals for coding, testing, and monitoring

  • System administration Monitor logs while performing maintenance tasks

Conclusion

The screen command is an essential tool for Linux users who need to manage multiple terminal sessions and keep processes running persistently. It provides powerful features like session detachment, window management, and screen splitting that greatly enhance productivity. Whether you're managing remote servers or working on complex local tasks, mastering screen will make your terminal workflow more efficient and reliable.

Updated on: 2026-03-17T09:01:38+05:30

799 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements