---
title: "Screen"
lang: "en"
author: "Mohammad Abu Mattar"
canonical: https://mkabumattar.com/screen
---

[Home](/)›[Cheatsheets](/cheatsheets)

Cheatsheets

# Screen

GNU Screen is a terminal multiplexer for managing multiple terminal sessions, windows, and panes within a single screen. It covers commands for session and window management, and for splitting.

7 Categories18 Sections36 ExamplesPublished: 01 Jan 2023Updated: 28 Feb 2025

ScreenTerminal MultiplexerSessionsWindowsDevelopment Tools

[Markdown for AI(opens in a new tab)](/screen/index.md "Open the plain-Markdown version of this page, for pasting into an AI tool")

Series

[Developer Environment & Tooling](/series/developer-environment--tooling)2/6

[PreviousGit](/cheatsheets/git)[NextTmux](/cheatsheets/tmux)

All posts in this series (6)

Cheatsheets6

1.  [Git](/cheatsheets/git)
2.  [ScreenYou are here](/cheatsheets/screen)
3.  [Tmux](/cheatsheets/tmux)
4.  [Vim](/cheatsheets/vim)
5.  [VS Code](/cheatsheets/vscode)
6.  [Python Virtual Environments Cheatsheet](/cheatsheets/python-venv)

## [Getting started](#getting-started)

GNU Screen is a terminal multiplexer that gives you:

-   **Sessions**: Full terminal environments that persist even if you disconnect
-   **Windows**: Multiple terminals (tabs) within a single session
-   **Splits**: Horizontal and vertical screen divisions for side-by-side work
-   **Copy/Paste**: Built-in text selection and clipboard management
-   **Automation**: Scripts to auto-setup complex terminal layouts

Start your first screen session:

Terminal window

```
screen -S development
```

Then detach with `Ctrl+A d` and reattach from anywhere:

Terminal window

```
screen -r development
```

## [Key concepts](#key-concepts)

**Sessions**: Independent workspaces that continue running even if you disconnect. Useful for long-running server processes and preserving work state.

**Windows**: Tabs within a session. Each window is a full terminal shell with independent directory and command history.

**Splits**: Horizontal regions within a window. Allows side-by-side terminals without creating new windows (though for complex panes, tmux may be better).

**Copy Mode**: Special mode for selecting and copying text from the scrollback buffer for pasting later.

## [Essential keybindings](#essential-keybindings)

All keybindings use the prefix key `Ctrl+A` (abbreviated as `C-a`):

### [Session management](#session-management)

-   `C-a d` - Detach from session (background)
-   `C-a D D` - Detach and logout
-   `C-a q` - Exit screen

### [Windows](#windows)

-   `C-a c` - Create new window
-   `C-a n` / `C-a p` - Next/previous window
-   `C-a [0-9]` - Jump to window number
-   `C-a w` - List all windows
-   `C-a k` - Kill current window
-   `C-a A` - Rename window

### [Splits and regions](#splits-and-regions)

-   `C-a S` - Split horizontally (regions)
-   `C-a |` - Split vertically (newer versions)
-   `C-a Tab` - Switch to next region
-   `C-a X` - Remove current region
-   `C-a Q` - Remove all regions

### [Copy and paste](#copy-and-paste)

-   `C-a [` - Enter copy/scroll mode
-   `Space` - Start selection (in copy mode)
-   `Enter` - Copy selection (in copy mode)
-   `C-a ]` - Paste copied text
-   `C-a =` - Show paste buffers

## [Common Screen setup](#common-screen-setup)

Install and create your configuration file `~/.screenrc`:

Terminal window

```
# ~/.screenrc - Essential configuration# Increase scrollback historydefscrollback 10000
# Enable 256-color terminalterm screen-256color
# Don't show startup messagestartup_message off
# Enable visual bell for notificationsvbell on
# Automatically detach on connection lossautodetach on
# Useful custom bindingsbind h select -1bind l select +1bind - split -hbind _ split -v
```

Load the config:

Terminal window

```
screen -c ~/.screenrc
```

## [Building a development session](#building-a-development-session)

Create a complete development environment automatically:

```
#!/bin/bash# dev-session.sh - Create development environment
SESSION="dev"screen -S "$SESSION" -d -m
# Create editor windowscreen -S "$SESSION" -X new-window -t "editor"screen -S "$SESSION" -p "editor" -X send-keys "cd ~/myproject && vim" Enter
# Create server windowscreen -S "$SESSION" -X new-window -t "server"screen -S "$SESSION" -p "server" -X send-keys "cd ~/myproject && npm start" Enter
# Create test windowscreen -S "$SESSION" -X new-window -t "test"screen -S "$SESSION" -p "test" -X send-keys "cd ~/myproject && npm test" Enter
# Attach and startscreen -r "$SESSION"
```

Run it anytime: `bash dev-session.sh`

## [Tips for productivity](#tips-for-productivity)

1.  **Use Named Sessions**: `screen -S projectname` is easier to remember than numbered sessions
2.  **Name Your Windows**: Use `C-a A` to name windows (editor, server, monitor)
3.  **Detach Don’t Exit**: Always use `C-a d` to detach, not `exit`, so session persists
4.  **Create Session Templates**: Save setup scripts for recurring project types
5.  **Organize by Project**: One session per project with windows for different tasks
6.  **Use Splits for Monitoring**: Split regions work well for watching logs while you work
7.  **Enable Scrollback**: Set `defscrollback 10000` in ~/.screenrc for adequate history
8.  **Combine with SSH**: Screen keeps long-running remote tasks alive over SSH

## [Quick reference: session lifecycle](#quick-reference-session-lifecycle)

Terminal window

```
# Create sessionscreen -S mywork
# Inside screen - work normally, then detachCtrl+A d
# Check sessionsscreen -ls
# Reattach to sessionscreen -r mywork
# Kill session when donescreen -S mywork -X quit
```

## [Screen vs Tmux](#screen-vs-tmux)

**Screen is better for:**

-   Simplicity and a smaller learning curve
-   Systems where tmux isn’t available
-   Simple split layouts (left/right only)
-   Older servers that predate tmux

**Tmux is better for:**

-   Complex pane management
-   Modern development workflows
-   Extensive plugin ecosystem
-   Latest terminal features

## [Resources](#resources)

-   Official GNU Screen Manual: [https://www.gnu.org/software/screen/](https://www.gnu.org/software/screen/)
-   Linux Manual Page: [https://linux.die.net/man/1/screen](https://linux.die.net/man/1/screen)
-   Practical Screen Tutorial: [https://www.rackaid.com/blog/linux-screen-tutorial-and-how-to/](https://www.rackaid.com/blog/linux-screen-tutorial-and-how-to/)

[Getting Started](#category-getting-started)

-   [Installation and Basics](#section-installation-and-basics)
-   [Understanding Screen Concepts](#section-understanding-screen-concepts)
-   [Creating Your First Session](#section-first-screen-session)

[Session Management](#category-session-management)

-   [Create and Attach Sessions](#section-create-and-attach-sessions)
-   [List and Monitor Sessions](#section-list-and-monitor-sessions)
-   [Kill and Destroy Sessions](#section-kill-and-destroy-sessions)

[Window Management](#category-window-management)

-   [Create and Switch Windows](#section-create-and-switch-windows)
-   [Manage and Close Windows](#section-manage-and-close-windows)
-   [Window Navigation Tips](#section-window-navigation-tips)

[Splitting Screens](#category-splitting-screens)

-   [Horizontal and Vertical Splits](#section-horizontal-vertical-splits)
-   [Navigate and Resize Splits](#section-navigate-and-resize-splits)
-   [Remove and Reset Splits](#section-remove-and-reset-splits)

[Copy/Paste and Scrolling](#category-copy-paste-scrolling)

-   [Copy Mode and Paste](#section-copy-mode-and-paste)
-   [Scrollback and Buffer Management](#section-scrollback-and-buffer-management)

[Advanced Commands](#category-advanced-commands)

-   [Configuration and Keybindings](#section-configuration-and-keybindings)
-   [Automation and Scripting](#section-automation-and-scripting)

[Tips and Tricks](#category-tips-and-tricks)

-   [Best Practices and Workflows](#section-best-practices-and-workflows)
-   [Common Workflows](#section-common-workflows)

No commands found

Try adjusting your search term

## Getting Started

Start using screen and learn basic concepts

### Installation and Basics

Install screen and understand what it does

#### Accessibility

Clear examples of installing and starting screen on different systems

#### Best Practices

-   Always name sessions with descriptive names for better organization
-   Use screen -ls regularly to check running sessions
-   Set SCREENDIR for custom session storage if needed

#### Common Errors

-   **screen is not installed:** Install with apt-get, yum, or brew depending on your OS

#### Keywords

installsetupstartlaunchscreen

[Learn more](https://www.gnu.org/software/screen/)

#### Install Screen on Linux

Installs GNU Screen terminal multiplexer and verifies the installation.

Code

Terminal window

```
# On Debian/Ubuntusudo apt-get install screen
# On RedHat/CentOS/Fedorasudo yum install screen
# On macOS with Homebrewbrew install screen
# Verify installationscreen --version
```

Execution

Terminal window

```
screen --version
```

Output

Terminal window

```
Screen version 4.09.00 (GNU) 23-Oct-22
```

-   Most Linux distributions include screen by default
-   Screen is lightweight and available on almost all Unix-like systems
-   No special permissions required to run screen

#### Start Screen without a session name

Launches Screen and shows running sessions.

Code

Terminal window

```
# Start a basic screen sessionscreen
# Start screen with UTF-8 supportscreen -U
# Start and list existing sessionsscreen -ls
```

Execution

Terminal window

```
screen -ls
```

Output

Terminal window

```
There is a screen on:  12345.pts-0.myhost  (Attached)
```

-   Creates a numbered session (starts from 0)
-   \-U flag enables UTF-8 character support
-   Attached status indicates active session

### Understanding Screen Concepts

Learn the hierarchical structure of screen

#### Accessibility

Visual explanation of screen's structure and terminology

#### Best Practices

-   Understand the difference between sessions and windows
-   Use meaningful window names for quick navigation
-   Keep related tasks in the same session

#### Common Errors

-   **no session to which to attach:** Create a new session first with screen -S sessionname

#### Keywords

conceptsstructurehierarchysessionswindows

[Learn more](https://linux.die.net/man/1/screen)

#### Understanding screen session and window hierarchy

Screen organizes your work into sessions containing multiple numbered windows.

Code

```
1Session (development)2├── Window 0 (shell)3├── Window 1 (editor)4├── Window 2 (build)5└── Window 3 (testing)
```

Execution

Terminal window

```
screen -ls development
```

Output

Terminal window

```
There are screens on:  12345.development  (Attached)
```

-   One session can contain many windows (like terminal tabs)
-   Unlike tmux, screen does not have panes (but can split horizontally)
-   Each window maintains its own shell environment and history

#### Check current screen setup

View information about your current screen session and windows.

Code

Terminal window

```
# Inside screen session - show infoCtrl+A i
# List all windows in current sessionCtrl+A w
# Show current window numberCtrl+A N
```

Execution

Terminal window

```
screen -version && echo 'Screen ready'
```

Output

Terminal window

```
Screen version 4.09.00 && Screen ready
```

-   Ctrl+A is the default command prefix in screen
-   Window list shows all open windows with their numbers and names
-   Most operations inside screen use Ctrl+A prefix

### Creating Your First Session

Create and manage your first screen session

#### Accessibility

Simple walkthrough of creating and entering a screen session

#### Best Practices

-   Use descriptive names like 'work', 'dev', 'server', 'build'
-   Detach sessions instead of killing them to preserve work
-   Reattach to preserved sessions later

#### Common Errors

-   **screen already exists:** Use screen -r -d to force reattach

#### Keywords

newcreatesessionstartnamed

[Learn more](https://man.archlinux.org/man/screen.1)

#### Create a named screen session

Creates a named screen session (with -S) that's easier to remember and reattach to.

Code

Terminal window

```
# Create a new named sessionscreen -S mywork
# Create session and execute commandscreen -S development -d -m "bash -c 'echo Starting development'"
# Create session in detached modescreen -S build -d
```

Execution

Terminal window

```
screen -S test -d
```

Output

Terminal window

```
[screen created]
```

-   \-S flag specifies the session name
-   \-d flag starts session detached (in background)
-   \-m flag allows starting with a command
-   Named sessions are easier to recall than numbered ones

#### Attach to a session

List all sessions and attach to the one you want to work with.

Code

Terminal window

```
# List all available sessionsscreen -ls
# Attach to a specific sessionscreen -r mywork
# Attach if already attached, multi-displayscreen -x mywork
# Force reattach if neededscreen -r -d mywork
```

Execution

Terminal window

```
screen -ls
```

Output

Terminal window

```
There are screens on:  12345.mywork    (Detached)  12346.development  (Attached)
```

-   \-r attaches to a detached session
-   \-x allows multiple users to view same session
-   \-d flag forces detach of other connections

## Session Management

Work with multiple screen sessions

### Create and Attach Sessions

Create new sessions and attach to existing ones

#### Accessibility

Step-by-step creation and attachment of sessions

#### Best Practices

-   Detach from sessions instead of exiting shell to preserve work
-   Use Ctrl+A d before closing terminal window
-   Keep session names consistent across your workflow

#### Common Errors

-   **cannot open /var/run/screen/permission denied:** Check screen permissions or use different screendir

#### Keywords

createnewattachstartsession

[Learn more](https://linux.die.net/man/1/screen)

#### Create multiple independent sessions

Create multiple independent screen sessions for different projects or tasks.

Code

Terminal window

```
# Create session for developmentscreen -S dev -d
# Create session for serversscreen -S servers -d
# Create session for testingscreen -S test -d
# List all created sessionsscreen -ls
```

Execution

Terminal window

```
screen -S workspace -d && screen -ls
```

Output

Terminal window

```
There is a screen on:  99999.workspace  (Detached)
```

-   Each session is completely independent
-   Sessions continue running even if you disconnect
-   Useful for long-running processes and server management

#### Attach and detach from sessions

Attach to your most recent session and navigate between windows.

Code

Terminal window

```
# Attach to an existing sessionscreen -r dev
# Inside screen, detach with:# Ctrl+A d (press Ctrl+A, release, then press D)
# Switch between windows in a session# Ctrl+A [0-9] to jump to window number# Ctrl+A n for next window# Ctrl+A p for previous window
```

Execution

Terminal window

```
screen -r
```

Output

Terminal window

```
[attached to session]
```

-   Detaching preserves your session, and everything keeps running
-   Ctrl+A is the command prefix for all screen operations
-   You can reattach to any detached session later

### List and Monitor Sessions

View and manage all running sessions

#### Accessibility

Clear display of session information and monitoring options

#### Best Practices

-   Regularly check session status with screen -ls
-   Use meaningful session names for easy identification
-   Monitor long-running processes regularly

#### Common Errors

-   **cannot find session:** Verify session name with screen -ls

#### Keywords

listlsmonitorcheckstatus

[Learn more](https://www.gnu.org/software/screen/manual/)

#### List all screen sessions with details

View all running screen sessions and their attachment status.

Code

Terminal window

```
# List all active sessionsscreen -ls
# Get more detailed session infoscreen -ls | grep -E '^\s+[0-9]'
# Check a specific sessionscreen -ls mywork
# List with additional statsps aux | grep SCREEN
```

Execution

Terminal window

```
screen -ls
```

Output

Terminal window

```
There are screens on:  12345.dev    (Attached)  12346.servers    (Detached)  12347.testing    (Detached)3 Sockets in /run/screen/S-user.
```

-   Attached means session is currently being viewed in a terminal
-   Detached sessions continue running in the background
-   Shows number of sockets (connection points) to session

#### Monitor and manage session processes

Monitor active processes and send commands to sessions remotely.

Code

Terminal window

```
# Inside screen - show window list infoCtrl+A w
# Show last 30 lines activityCtrl+A g
# Display current screen sizeecho $LINES x $COLUMNS
# Kill a session from outsidescreen -S mywork -X quit
# Send command to detached sessionscreen -S mywork -X send-keys "ls -la" Enter
```

Execution

Terminal window

```
screen -S worker -X send-keys "echo hello" Enter
```

Output

Terminal window

```
hello
```

-   \-X allows sending commands to sessions without attaching
-   send-keys can execute commands in detached sessions
-   Useful for automation and monitoring

### Kill and Destroy Sessions

Terminate sessions and clean up resources

#### Accessibility

Safe methods to end sessions and preserve data

#### Best Practices

-   Always detach before closing terminal to preserve session
-   Use exit command gracefully to close sessions
-   Run screen -wipe periodically to clean dead sessions

#### Common Errors

-   **cannot create socket:** Run screen -wipe to clean dead sessions

#### Keywords

killquitterminatedestroyend

[Learn more](https://linux.die.net/man/1/screen)

#### Properly terminate screen sessions

Terminate screen sessions cleanly or forcefully when needed.

Code

Terminal window

```
# Kill session from outsidescreen -S mywork -X quit
# Inside screen, exit shell to kill sessionexit
# Inside screen, use Ctrl+A k to kill current windowCtrl+A k
# Force kill a stuck sessionkill -9 $(pgrep -f 'SCREEN.*mywork')
# Clean up all dead sessionsscreen -wipe
```

Execution

Terminal window

```
screen -S temp -d && screen -S temp -X quit && screen -ls
```

Output

Terminal window

```
No Sockets found.
```

-   exit command closes the shell and ends the session cleanly
-   Ctrl+A k kills only current window, not entire session
-   \-X quit is cleanest remote termination method
-   kill -9 should be last resort for stuck sessions

#### Handle zombie and dead sessions

Clean up dead or orphaned screen sessions.

Code

Terminal window

```
# List sessions including dead onesscreen -ls
# Remove dead sessionsscreen -wipe
# Clear out orphaned screen processeskillall -v screen
# Verify cleanupscreen -ls
```

Execution

Terminal window

```
screen -wipe
```

Output

Terminal window

```
[dead sessions removed]
```

-   Dead sessions occur when session crashes or terminal closes abruptly
-   screen -wipe removes dead sessions automatically
-   Only use killall screen if absolutely necessary

## Window Management

Create and navigate multiple windows within a session

### Create and Switch Windows

Create new windows and navigate between them

#### Accessibility

Easy window creation and switching techniques

#### Best Practices

-   Create windows for different logical tasks (editor, build, test, monitor)
-   \[object Object\]
-   Keep frequently used windows numbered 0-3 for quick access

#### Common Errors

-   **window already exists:** Use screen -ls to see existing windows

#### Keywords

createnewwindowswitchnavigatejump

[Learn more](https://linux.die.net/man/1/screen)

#### Create new windows in a session

Create multiple windows within a screen session for different tasks.

Code

Terminal window

```
# Inside screen - create new windowCtrl+A c
# Create window with a specific shell commandCtrl+A :screen -t "editor" vim
# Create window and name itCtrl+A :title editor
# Create numbered window sequencefor i in {1..5}; do  screen -S dev -X new-window -t dev:$idone
```

Execution

Terminal window

```
echo "Use Ctrl+A c inside screen to create windows"
```

Output

Terminal window

```
Use Ctrl+A c inside screen to create windows
```

-   Each window is independent with its own shell
-   Window numbering starts at 0 by default
-   Windows can have friendly names for easy identification
-   \-t flag specifies window title during creation

#### Switch between windows efficiently

Navigate quickly between windows using keyboard shortcuts.

Code

Terminal window

```
# Jump to window by number (0-9)Ctrl+A 0  # Jump to window 0Ctrl+A 1  # Jump to window 1Ctrl+A 2  # Jump to window 2
# Move to next/previous windowCtrl+A n  # Next windowCtrl+A p  # Previous window
# Switch to last active windowCtrl+A Ctrl+A
# List all windowsCtrl+A w
```

Execution

Terminal window

```
echo "Inside screen session use Ctrl+A w to see all windows"
```

Output

Terminal window

```
Inside screen session use Ctrl+A w to see all windows
```

-   Ctrl+A w shows visual list of all windows
-   Ctrl+A Ctrl+A toggles between last two windows
-   Direct number access (Ctrl+A 0-9) is fastest for frequent windows

### Manage and Close Windows

Rename, close, and organize windows

#### Accessibility

Methods to organize and close windows

#### Best Practices

-   Use clear naming convention for windows
-   Don't have too many windows, keep to 5-10 max
-   Close unused windows to reduce clutter

#### Common Errors

-   **cannot kill only window:** Session ends when you kill the last window

#### Keywords

managerenameclosekillarrange

[Learn more](https://www.gnu.org/software/screen/manual/)

#### Rename and manage windows

Rename windows to organize and identify them clearly.

Code

Terminal window

```
# Rename current window (inside screen)Ctrl+A A
# Change window title in command modeCtrl+A :title newname
# Rename from shell (outside screen)screen -S mywork -p number -X title newname
# Move window to different positionCtrl+A :number position
```

Execution

Terminal window

```
echo "Press Ctrl+A A inside screen to rename current window"
```

Output

Terminal window

```
Press Ctrl+A A inside screen to rename current window
```

-   Ctrl+A A opens rename prompt in current window
-   window names help identify purpose at a glance
-   Can set window titles programmatically

#### Close windows and manage cleanup

Close and remove windows when no longer needed.

Code

Terminal window

```
# Kill current window (inside screen)Ctrl+A k
# Close window with confirmationCtrl+A K
# Exit shell in window (closes window)exit
# Remove specific window from shellscreen -S mywork -p 2 -X kill
# List and close all windows except currentCtrl+A :killall
```

Execution

Terminal window

```
echo "Use Ctrl+A k to kill current window"
```

Output

Terminal window

```
Use Ctrl+A k to kill current window
```

-   Ctrl+A k kills window immediately
-   Ctrl+A K asks for confirmation before killing
-   exit command also closes the window

### Window Navigation Tips

Advanced techniques for efficient window navigation

#### Accessibility

Shortcuts and tips for rapid window switching

#### Best Practices

-   Map shortcuts to your muscle memory
-   Use vim-like h/l for left/right navigation
-   Test shortcuts before integrating into workflow

#### Common Errors

-   **keybinding not working:** Check ~/.screenrc syntax and reload screen

#### Keywords

navigatejumpswitchjumpefficient

[Learn more](https://linux.die.net/man/1/screen)

#### Speed up window switching

Switch windows quickly using direct number access.

Code

Terminal window

```
# Quick jump to numbered windowsCtrl+A 0  # Fastest for frequently used windowsCtrl+A 1Ctrl+A 9
# Cycle through windowsCtrl+A n      # NextCtrl+A p      # PreviousCtrl+A Ctrl+A # Last active
# List windows with full detailsCtrl+A w
```

Execution

Terminal window

```
echo "For windows 0-9, use Ctrl+A + number"
```

Output

Terminal window

```
For windows 0-9, use Ctrl+A + number
```

-   Direct number access is fastest for frequent switches
-   Keep important windows at positions 0-3
-   Ctrl+A Ctrl+A is useful for two-window workflows

#### Configure custom window switching

Customize keybindings for faster window navigation in your workflow.

Code

Terminal window

```
# In ~/.screenrc - create custom bindings# Example - use Alt+number for windowsbind 'M-1' select 1bind 'M-2' select 2bind 'M-3' select 3
# Or use simpler keybindingsbind 'h' select -1bind 'l' select +1
```

Execution

Terminal window

```
echo "Configure .screenrc for custom keybindings"
```

Output

Terminal window

```
Configure .screenrc for custom keybindings
```

-   Custom keybindings require ~/.screenrc configuration
-   M- prefix refers to Meta/Alt key
-   Changes take effect after screen restart

## Splitting Screens

Split windows horizontally and vertically

### Horizontal and Vertical Splits

Split windows in different directions

#### Accessibility

Clear visual guidance for creating splits

#### Best Practices

-   Keep splits simple, 2-3 regions per window is ideal
-   Use consistent window numbers across splits
-   Remember layouts for common workflows

#### Common Errors

-   **cannot split - too small:** Enlarge terminal window before splitting

#### Keywords

splithorizontalverticalregionpane

[Learn more](https://linux.die.net/man/1/screen)

#### Create screen splits

Create horizontal and vertical splits in screen windows.

Code

Terminal window

```
# Split horizontally (top/bottom)Ctrl+A S
# Split vertically (left/right)Ctrl+A |
# Create complex layoutsCtrl+A S      # First split - creates top regionCtrl+A Tab    # Move to new regionCtrl+A c      # Create window in top regionCtrl+A S      # Split again
# Remove current splitCtrl+A X
```

Execution

Terminal window

```
echo "Use Ctrl+A S for horizontal, Ctrl+A | for vertical"
```

Output

Terminal window

```
Use Ctrl+A S for horizontal, Ctrl+A | for vertical
```

-   Horizontal split creates top/bottom regions
-   Vertical split creates left/right regions (in newer screens)
-   Each split region can display different windows
-   Vertical split may not work in older screen versions

#### Manage complex split layouts

Create and manage multiple grouped split regions.

Code

Terminal window

```
# Split the window in halfCtrl+A S
# Switch to bottom regionCtrl+A Tab
# Create another window in bottomCtrl+A c
# Split bottom region verticallyCtrl+A |
# Navigate to each regionCtrl+A Tab  # Cycle through regions
# Remove current regionCtrl+A X
```

Execution

Terminal window

```
echo "Layouts: press Tab to cycle through split regions"
```

Output

Terminal window

```
Layouts: press Tab to cycle through split regions
```

-   Each split region is independent
-   Tab cycles through different regions
-   Better than tmux for simple side-by-side use cases

### Navigate and Resize Splits

Move between and resize split regions

#### Accessibility

Clear navigation through multiple split regions

#### Best Practices

-   Arrange regions by importance, with the largest for the main task
-   Keep monitor task in smaller secondary region
-   Reset layout when splits get confusing

#### Common Errors

-   **region too small to navigate:** Resize larger with Ctrl+A + keys

#### Keywords

navigateresizeregionmovearrange

[Learn more](https://www.gnu.org/software/screen/manual/)

#### Navigate between split regions

Move between split regions with Tab.

Code

Terminal window

```
# Move to next regionCtrl+A Tab
# Move to top regionCtrl+A Ctrl+I
# Display current region numberCtrl+A Shift+I
# Switch to specific window in regionCtrl+A 0-9  (in focused region)
# Rotate windows among regionsCtrl+A C-T
```

Execution

Terminal window

```
echo "Tab to navigate regions, then 0-9 to switch windows"
```

Output

Terminal window

```
Tab to navigate regions, then 0-9 to switch windows
```

-   Tab is the primary method to move between regions
-   Once in a region, number keys switch windows within it
-   Visual feedback shows active region highlighting

#### Resize split regions

Adjust the size of split regions.

Code

Terminal window

```
# Resize current region (make larger)Ctrl+A +  (expand downward)Ctrl+A -  (shrink)
# Auto-fit region to contentCtrl+A F
# Equalize all region sizesCtrl+A E
# Fine-tune sizingCtrl+A :resize height
```

Execution

Terminal window

```
echo "Use +/- keys to resize regions"
```

Output

Terminal window

```
Use +/- keys to resize regions
```

-   Plus/minus adjust region boundaries dynamically
-   Resize affects the current focused region
-   Works better in newer screen versions

### Remove and Reset Splits

Clear splits and reset layouts

#### Accessibility

Easy methods to clean up split configurations

#### Best Practices

-   Save common layouts for quick recall
-   \[object Object\]
-   Test layout loading before relying on it

#### Common Errors

-   **layout save not supported:** Update to screen 4.01 or newer

#### Keywords

removeresetclearquitlayout

[Learn more](https://linux.die.net/man/1/screen)

#### Remove and reset split regions

Clean up and remove screen splits when needed.

Code

Terminal window

```
# Remove current regionCtrl+A X
# Remove all splits (show single region)Ctrl+A Q
# Close all regions except currentCtrl+A :only
# Reset layout to defaultCtrl+A :layout reset
```

Execution

Terminal window

```
echo "Ctrl+A X to remove current region, Q to remove all"
```

Output

Terminal window

```
Ctrl+A X to remove current region, Q to remove all
```

-   Ctrl+A X removes only current region
-   Ctrl+A Q removes all splits in window
-   Windows are preserved even when splits removed

#### Save and restore layouts

Save and restore frequently used split configurations.

Code

Terminal window

```
# Save current layout (named layout)Ctrl+A :layout save workname
# List saved layoutsCtrl+A :layout list
# Restore saved layoutCtrl+A :layout load workname
# Switch between layoutsCtrl+A :layout select workname
```

Execution

Terminal window

```
echo "Layout save/restore requires configuration"
```

Output

Terminal window

```
Layout save/restore requires configuration
```

-   Layout save feature available in screen 4.01+
-   Useful for repeating complex split setups
-   Saves time in daily workflows

## Copy/Paste and Scrolling

Copy text and navigate scrollback buffer

### Copy Mode and Paste

Copy text from screen and paste it back

#### Accessibility

Step-by-step copying and pasting text

#### Best Practices

-   Use vim keybindings for faster selection in copy mode
-   Name important buffers for easy recall
-   Copy error messages for troubleshooting later

#### Common Errors

-   **nothing in paste buffer:** Use Ctrl+A \[ to copy text first

#### Keywords

copypastetextclipboardbuffer

[Learn more](https://linux.die.net/man/1/screen)

#### Enter copy mode and select text

Enter copy mode to select and copy text from screen history.

Code

Terminal window

```
# Enter copy/scroll modeCtrl+A [
# Move cursor in copy mode- Use arrow keys to navigate- Space to start selection- Enter to copy selection- Or use G to go to bottom
# Exit copy mode without copyingEscape
# Navigate in copy modeh j k l  (vim style - if configured)b      (back word)f      (forward word)
```

Execution

Terminal window

```
echo "Press Ctrl+A [ to enter copy mode"
```

Output

Terminal window

```
Press Ctrl+A [ to enter copy mode
```

-   Copy mode shows scrollback buffer
-   Can mark and copy multiple times without exiting
-   Text stays in screen clipboard for pasting

#### Paste text and manage buffers

Paste previously copied text and manage multiple buffers.

Code

Terminal window

```
# Paste last copied textCtrl+A ]
# Show available paste buffersCtrl+A =
# Paste from specific bufferCtrl+A :paste buffer_name
# Copy directly from commandecho "text" | Ctrl+A [
```

Execution

Terminal window

```
echo "Use Ctrl+A ] to paste copied text"
```

Output

Terminal window

```
Use Ctrl+A ] to paste copied text
```

-   Ctrl+A \] pastes last copied selection
-   Multiple buffers allow you to save different text snippets
-   Clipboard is separate from system clipboard

### Scrollback and Buffer Management

Navigate history and manage scrollback buffers

#### Accessibility

Methods to view and navigate scrollback history

#### Best Practices

-   Set scrollback to 10000 for normal development work
-   Search scrollback regularly to find past commands
-   Clear scrollback when debugging sensitive information

#### Common Errors

-   **pageup not working in copy mode:** May be bound to different key, check with Ctrl+A ?

#### Keywords

scrollhistorybufferbackscrollnavigate

[Learn more](https://www.gnu.org/software/screen/manual/)

#### Navigate scrollback buffer

Navigate and search through terminal history.

Code

Terminal window

```
# Enter scrollback (scroll up in history)Ctrl+A [
# Scroll up in historyPage Up  or  B
# Scroll down in historyPage Down  or  F
# Go to top of bufferg      (go to top)G      (go to bottom)
# Search in scrollback/pattern   (forward search)?pattern   (backward search)n          (next match)
```

Execution

Terminal window

```
echo "Ctrl+A [ enters scrollback mode"
```

Output

Terminal window

```
Ctrl+A [ enters scrollback mode
```

-   Scrollback allows viewing past output
-   Search helps find specific text in history
-   Default scrollback is usually 100-1000 lines

#### Adjust scrollback buffer size

Configure and manage scrollback buffer size.

Code

Terminal window

```
# In ~/.screenrc - increase historydefscrollback 10000
# View current buffer sizeCtrl+A i
# Clear scrollback bufferCtrl+A C  (clears screen but not buffer)
# Set buffer per-sessionscreen -S work -X scrollback 5000
```

Execution

Terminal window

```
echo "Edit ~/.screenrc to set defscrollback"
```

Output

Terminal window

```
Edit ~/.screenrc to set defscrollback
```

-   Larger buffers use more memory
-   10000 lines is good default for most work
-   Per-window scrollback available in newer screen

## Advanced Commands

Advanced screen configuration and automation

### Configuration and Keybindings

Configure screen with ~/.screenrc

#### Accessibility

Practical configuration examples for common use cases

#### Best Practices

-   Start with minimal ~/.screenrc and add gradually
-   Use consistent keybinding patterns across tools
-   Document non-obvious bindings in config file

#### Common Errors

-   **unknown command in screenrc:** Check syntax with 'screen -c ~/.screenrc' before committing

#### Keywords

configkeybindingcustomizescreenrcsettings

[Learn more](https://linux.die.net/man/1/screen)

#### Create essential ~/.screenrc configuration

Configure screen with common settings in ~/.screenrc.

Code

Terminal window

```
# ~/.screenrc example# Increase scrollback bufferdefscrollback 10000
# Set terminal typeterm screen-256color
# Enable 256 colorstermcapeinfo xterm-256color 'Co#256:AB=\E[48;5;%dm:AF=\E[38;5;%dm'
# Disable startup messagestartup_message off
# Set default window titleshelltitle '$ |bash'
# Automatically detach on hangupautodetach on
# Enable visual bellvbell on
# Set the command characterescape ^Aa
```

Execution

Terminal window

```
cat ~/.screenrc | head -15
```

Output

Terminal window

```
defscrollback 10000term screen-256colorstartup_message off
```

-   ~/.screenrc is sourced when screen starts
-   Settings apply to all new screen sessions
-   Changes require restarting screen to take effect
-   Some settings can be overridden per-session

#### Custom keybindings configuration

Create custom keybindings matching your preferred workflow.

Code

Terminal window

```
# ~/.screenrc - custom keybindings# Create new window (override default)bind c new-window
# Vim-style navigationbind h select -1bind l select +1bind j prevbind k next
# Alt+number for windowsbind '^[1' select 1bind '^[2' select 2bind '^[3' select 3
# Custom split bindingsbind | split -vbind - split
# Reload configbind r source ~/.screenrc 'Reload complete'
```

Execution

Terminal window

```
echo "Add bindings to ~/.screenrc"
```

Output

Terminal window

```
Add bindings to ~/.screenrc
```

-   Control characters use format ^X (Ctrl+X)
-   Meta (Alt) characters use format ^\[
-   Test new bindings before making permanent

### Automation and Scripting

Automate screen with shell commands and scripts

#### Accessibility

Practical automation examples for daily tasks

#### Best Practices

-   Create templates for common session setups
-   Log session activity for automation tracking
-   Use descriptive window names in scripts

#### Common Errors

-   **broken pipe when sending to session:** Verify session exists with screen -ls

#### Keywords

automatescriptcommandsend-keysbatch

[Learn more](https://www.gnu.org/software/screen/manual/)

#### Automate session creation with scripts

Automate screen session setup with shell scripts.

Code

```
#!/bin/bash# Create automated development environmentSESSION="dev"
# Create session with first windowscreen -S "$SESSION" -d -m
# Create and name windowsscreen -S "$SESSION" -X new-window -t "editor"screen -S "$SESSION" -X new-window -t "build"screen -S "$SESSION" -X new-window -t "monitor"
# Send initial commandsscreen -S "$SESSION" -p "editor" -X send-keys "vim" Enterscreen -S "$SESSION" -p "build" -X send-keys "cd ~/project" Enter
# Attach to sessionscreen -r "$SESSION"
```

Execution

Terminal window

```
echo "Script automates session setup"
```

Output

Terminal window

```
Script automates session setup
```

-   \-p option specifies target window
-   send-keys sends keystrokes to session
-   Can chain multiple commands in script
-   Useful for standardizing team workflows

#### Send commands to running session

Send commands to active or background sessions remotely.

Code

Terminal window

```
# Send commands to unnamed sessionscreen -S mysession -X send-keys "ls -la" Enter
# Send to specific windowscreen -S mysession -p 2 -X send-keys "npm test" Enter
# Send without Enter (for typing)screen -S dev -X send-keys "git status"
# Run monitoring command#!/bin/bashwhile true; do  screen -S monitor -X send-keys "clear" Enter  date | screen -S monitor -X send-keys -  sleep 10done
```

Execution

Terminal window

```
echo "Use -X send-keys for automation"
```

Output

Terminal window

```
Use -X send-keys for automation
```

-   Useful for deployment and monitoring automation
-   Can integrate with cron for scheduled tasks
-   Combine with pipes for complex workflows

## Tips and Tricks

Best practices and productivity tips

### Best Practices and Workflows

Recommended patterns for effective screen usage

#### Accessibility

Practical tips for daily screen usage

#### Best Practices

-   One session per major project or environment
-   \[object Object\]
-   Detach before closing terminal to preserve sessions
-   Reattach to same session for consistency

#### Common Errors

-   **lost my session after terminal closed:** Never kill the terminal, always detach first with Ctrl+A d

#### Keywords

bestpracticestipsworkflowproductivity

[Learn more](https://linux.die.net/man/1/screen)

#### Organize projects into sessions

Organize work into sessions by project with task-specific windows.

Code

Terminal window

```
# Create sessions for different projectsscreen -S frontend -dscreen -S backend -dscreen -S devops -d
# Each session contains logical windows# frontend sessionscreen -S frontend -X new-window -t "editor"screen -S frontend -X new-window -t "dev-server"screen -S frontend -X new-window -t "tests"
# backend sessionscreen -S backend -X new-window -t "api"screen -S backend -X new-window -t "database"screen -S backend -X new-window -t "logs"
# List all project sessionsscreen -ls | grep -E '(frontend|backend|devops)'
```

Execution

Terminal window

```
echo "Use sessions for projects, windows for tasks"
```

Output

Terminal window

```
Use sessions for projects, windows for tasks
```

-   Sessions isolate different projects
-   Windows organize tasks within a project
-   Easy to switch context without losing state
-   Works well for polyglot development

#### Monitor multiple servers from one session

Monitor multiple systems from one session with separate windows.

Code

Terminal window

```
# Create monitoring sessionscreen -S servers -d
# Create windows for each serverfor server in web db cache load; do  screen -S servers -X new-window -t "$server"  screen -S servers -p "$server" -X send-keys \    "ssh user@${server}.example.com" Enterdone
# Create summary windowscreen -S servers -X new-window -t "summary"
# Monitor all with watch commandscreen -S servers -p summary -X send-keys \  "watch -n 5 'for s in web db cache load; do echo $s; ssh user@${s} uptime; done'" Enter
```

Execution

Terminal window

```
echo "Use same session for related monitoring"
```

Output

Terminal window

```
Use same session for related monitoring
```

-   One session per environment reduces context switching
-   Windows allow monitoring different aspects
-   Good for sysadmin and DevOps workflows

### Common Workflows

Ready-to-use patterns for typical tasks

#### Accessibility

Copy-paste examples for common development tasks

#### Best Practices

-   Create template scripts for repetitive setups
-   Save 3-5 most useful session templates
-   Document any non-obvious shortcuts

#### Common Errors

-   **commands don't run in automation script:** Add delays with sleep between send-keys calls

#### Keywords

workflowpatternexamplecommonready

[Learn more](https://www.gnu.org/software/screen/manual/)

#### Web development workflow

Create a standardized web development environment.

Code

```
#!/bin/bash# Web development setupSESSION="web"screen -S "$SESSION" -d -m
# Window 0: Code editorscreen -S "$SESSION" -X new-window -t "editor"screen -S "$SESSION" -p "editor" -X send-keys "cd ~/projects/myapp && vim" Enter
# Window 1: Dev serverscreen -S "$SESSION" -X new-window -t "server"screen -S "$SESSION" -p "server" -X send-keys "cd ~/projects/myapp && npm start" Enter
# Window 2: Testsscreen -S "$SESSION" -X new-window -t "test"screen -S "$SESSION" -p "test" -X send-keys "cd ~/projects/myapp && npm test" Enter
# Window 3: Git/shellscreen -S "$SESSION" -X new-window -t "shell"screen -S "$SESSION" -p "shell" -X send-keys "cd ~/projects/myapp && bash" Enter
# Attach to sessionscreen -r "$SESSION"
```

Execution

Terminal window

```
echo "Save as startup script for web projects"
```

Output

Terminal window

```
Save as startup script for web projects
```

-   Saves time on setup for new projects
-   Keeps window organization consistent
-   Easy to extend with more tools

#### System administration quick reference

Organize server management tasks with splits.

Code

Terminal window

```
# Quick reference for sysadmins# Session per environment:screen -S prod   # Production monitoringscreen -S staging  # Staging environmentscreen -S dev    # Development/testing
# In each session, split regions for:# - Top: Monitoring (top, htop, watch)# - Bottom-left: Logs (tail -f logfile)# - Bottom-right: Services (systemctl commands)
# Workflow in session:Ctrl+A S           # Split horizontallyCtrl+A c           # Create window in topCtrl+A Tab         # Move to bottomCtrl+A |           # Split verticallyCtrl+A c           # Create window bottom-leftCtrl+A Tab         # Move bottom-rightCtrl+A c           # Create window bottom-right
# Load baseline services in backgroundscreen -d -m "systemctl status"
```

Execution

Terminal window

```
echo "Sysadmin can leverage splits for complex monitoring"
```

Output

Terminal window

```
Sysadmin can leverage splits for complex monitoring
```

-   Splits allow monitoring multiple aspects simultaneously
-   Useful for complex troubleshooting
-   Saves window switching time during incidents

Was this useful?

## Tags

#Screen#Terminal Multiplexer#Sessions#Windows#Development Tools

## Share

[Facebook](https://facebook.com/sharer/sharer.php?u=https%3A%2F%2Fmkabumattar.com%2Fcheatsheets%2Fscreen "Share on Facebook")[Twitter](https://twitter.com/intent/tweet/?text=Screen&url=https%3A%2F%2Fmkabumattar.com%2Fcheatsheets%2Fscreen "Share on Twitter")[LinkedIn](https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Fmkabumattar.com%2Fcheatsheets%2Fscreen&title=Screen&summary=GNU%20Screen%20is%20a%20terminal%20multiplexer%20for%20managing%20multiple%20terminal%20sessions%2C%20windows%2C%20and%20panes%20within%20a%20single%20screen.%20It%20covers%20commands%20for%20session%20and%20window%20management%2C%20and%20for%20splitting.&source=https://mkabumattar.com "Share on LinkedIn")[WhatsApp](https://wa.me/?text=Screen%20https%3A%2F%2Fmkabumattar.com%2Fcheatsheets%2Fscreen "Share on WhatsApp")[Telegram](https://t.me/share/url?url=https%3A%2F%2Fmkabumattar.com%2Fcheatsheets%2Fscreen&text=Screen "Share on Telegram")[Reddit](https://www.reddit.com/submit?url=https%3A%2F%2Fmkabumattar.com%2Fcheatsheets%2Fscreen&title=Screen "Share on Reddit")[Hacker News](http://news.ycombinator.com/submitlink?u=https%3A%2F%2Fmkabumattar.com%2Fcheatsheets%2Fscreen&t=Screen "Share on Hacker News")[Pinterest](https://pinterest.com/pin/create/button/?url=https%3A%2F%2Fmkabumattar.com%2Fcheatsheets%2Fscreen&media=&description=GNU%20Screen%20is%20a%20terminal%20multiplexer%20for%20managing%20multiple%20terminal%20sessions%2C%20windows%2C%20and%20panes%20within%20a%20single%20screen.%20It%20covers%20commands%20for%20session%20and%20window%20management%2C%20and%20for%20splitting. "Share on Pinterest")[Email](<mailto:?subject=Screen&body=Check out this article: https%3A%2F%2Fmkabumattar.com%2Fcheatsheets%2Fscreen>)

## Comments

## You might also enjoy

More posts on similar topics

## [Tmux](/cheatsheets/tmux)

-   [Mohammad Abu Mattar](/authors/mohammad-abu-mattar)
-   Terminal
-   Tmux
-   Tools
-   Development
-   System Administration

Tmux is a terminal multiplexer for managing multiple terminal sessions, windows, and panes within a single screen. This cheatsheet covers the commands, keybindings, and configuration options for every

#Tmux#Terminal Multiplexer#Sessions+3 tags

[read more](/cheatsheets/tmux)

## [Vim](/cheatsheets/vim)

-   [Mohammad Abu Mattar](/authors/mohammad-abu-mattar)
-   Editor
-   Text Editor
-   Terminal
-   Command Line
-   Productivity

Vim is a highly configurable text editor built to make creating and changing any kind of text very efficient. It is included as "vi" with most UNIX systems. The sections below cover Vim commands, sho

#Editor#Vim#Text Editor+3 tags

[read more](/cheatsheets/vim)

## [Git](/cheatsheets/git)

-   [Mohammad Abu Mattar](/authors/mohammad-abu-mattar)
-   Version Control
-   Git
-   SCM
-   Collaboration
-   Development Tools

Git is a distributed version control system. Developers use it to track code changes, collaborate with teams, and manage project history. Most software teams build their workflow around it. Key co

#Git#Version Control#Branches+5 tags

[read more](/cheatsheets/git)

## [Cron](/cheatsheets/cron)

-   [Mohammad Abu Mattar](/authors/mohammad-abu-mattar)
-   Terminal
-   System Administration
-   Linux
-   Scheduling
-   Automation
-   Tools

Quick reference Field layout Min Hour Day Month Weekday Command\* /path/to/command ┬ ┬ ┬ ┬ ┬ │ │ │ │ └───── Weekday (0=Sunday,

#Cron#Crontab#Scheduling+3 tags

[read more](/cheatsheets/cron)

## [Netcat](/cheatsheets/nc)

-   [Mohammad Abu Mattar](/authors/mohammad-abu-mattar)
-   Terminal
-   Networking
-   Tools
-   System Administration
-   Port Scanning

This netcat cheatsheet covers TCP/UDP connections, file transfers, port scanning, banner grabbing, and advanced network operations.

#Netcat#Nc#Network+4 tags

[read more](/cheatsheets/nc)

## [Netstat](/cheatsheets/netstat)

-   [Mohammad Abu Mattar](/authors/mohammad-abu-mattar)
-   Terminal
-   System Administration
-   Linux
-   Networking
-   Tools

This netstat cheatsheet covers six categories, with worked examples and troubleshooting steps in each.

#Netstat#Network#Connections+3 tags

[read more](/cheatsheets/netstat)

6 related posts
