Enhance Your Terminal Workflow With A Terminal Multiplexer (screen)

The terminal multiplexer screen is an invaluable tool for anyone looking to enhance their command-line productivity.
Enhance Your Terminal Workflow With A Terminal Multiplexer (screen)

Introduction

The terminal multiplexer screen is an invaluable tool for anyone looking to enhance their command-line productivity. Whether you're managing a home lab, frequently using SSH to connect to remote servers, or simply looking to keep your terminal sessions organized, screen offers a powerful solution. This versatile utility allows you to manage multiple terminal sessions within a single window, enabling you to seamlessly switch between tasks without cluttering your workspace.

One of the standout features of screen is its ability to keep sessions active even after disconnecting from an SSH session. This means you can start a long-running process, detach from the session, and reattach later without interrupting your work. This is particularly beneficial for home lab enthusiasts and system administrators who need to ensure the continuous operation of scripts and services.

In this guide, I will walk you through the installation and basic usage of screen Ubuntu. Although this guide is tailored for Ubuntu users, the principles and commands are largely applicable across different Linux distributions, with only minor variations in the installation process. By the end of this guide, you'll be equipped to leverage screen to boost your productivity and streamline your terminal management.

Installation

First, you need to install screen, you can do this using the following command:

sudo apt-get update
sudo apt-get install screen
This is built-in to MacOS and ready to be used. Technically speaking you can used this on Windows within WSL (WIndows Subsystem for Linux), however, you can replicate the same effect by using Windows Terminal and just opening up separate tabs.

Basic Usage

Once screen is installed, you can start using it. Here are some basic commands and concepts to get you started:

Starting a Screen Session

To start a new screen session, simply type:

screen

You will be taken to a new terminal session. From here, you can run any command or start any process you want.

Naming a Screen Session

It's often useful to give your screen session a name so you can easily identify it later:

# create a new session with a name to identify it for later use
screen -S session_name

Detaching from a Screen Session

You can detach from a running screen and return to the original terminal while leaving it running in the background.

# to detach from a running screen
# press
Control + A
# then press
Control + D

Listing Screen Sessions

To see a list of all your active screen sessions with their running ID you can use the following command:

screen -ls

Reattaching to a Screen Session

To reattach to a screen session, you can use the session_id or the session_name to reattach to:

# replace session_id with the session ID
screen -r session_id

# if you know the name you can use that instead, replace session_name with the name of the session
screen -r session_name

Exiting a Screen Session

To exit a screen session, simply type exit within the session or press:

Control + D

Advanced Features

Here are some additional commands and features of screen:

Creating Windows Within a Screen Session

You can create multiple windows within a single-screen session:

  • Create a new window: Ctrl + A, then C
  • Switch between windows: Ctrl + A, then N (next window), Ctrl + A, then P (previous window)
  • List windows: Ctrl + A, then W

Splitting the Screen

You can split the screen to view multiple windows simultaneously:

  • Split horizontally: Ctrl + A, then S
  • Split vertically: Ctrl + A, then | (pipe symbol)
  • Navigate between splits: Ctrl + A, then Tab
  • Close the current split: Ctrl + A, then Q

Sending Commands to All Windows

To send a command to all windows in a screen session:

  • Enter command mode: Ctrl + A, then :
  • Broadcast mode: at # stuff "your_command\n"

Conclusion

screen is an essential tool for anyone looking to enhance their command-line productivity, particularly for managing multiple terminal sessions and long-running processes. This guide has demonstrated how to install screen on Ubuntu, create and detach sessions, and utilize some of its advanced features. Whether you're managing a home lab, frequently using SSH, or simply aiming to keep your terminal sessions organized, screen provides a robust solution.

By leveraging the capabilities of screen, you can keep your terminal workspace tidy and ensure that critical tasks continue running even when you're disconnected. With its ability to maintain active sessions and streamline your workflow, screen is a valuable addition to any Linux user's toolkit. Feel free to explore further and make the most of this powerful terminal multiplexer to boost your productivity and efficiency.


Full Disclosure

Most of this article is comprised of facts and opinions. The featured background image was created by andyoneru and is available on Unsplash. I added a blur and a gradient overlay with some text. The following images have been pulled or screenshotted from the respective websites/applications. I do not own this content.

Subscribe to Hi! I'm Harley newsletter and stay updated.

Don't miss anything. Get all the latest posts delivered straight to your inbox. It's free!
Great! Check your inbox and click the link to confirm your subscription.
Error! Please enter a valid email address!