Skip to content
screen and tmux Commands in Linux — Terminal Multiplexers

screen and tmux Commands in Linux — Terminal Multiplexers

DodaTech Updated Jun 20, 2026 7 min read

screen and tmux are terminal multiplexers that let you run multiple shell sessions in a single terminal, keep processes running after you disconnect, and reattach later from a different machine — essential for remote server work.

What You’ll Learn

You’ll create named sessions, detach and reattach, split panes horizontally and vertically, manage multiple windows, use scrollback mode, configure tmux, and keep long-running jobs alive across SSH disconnections.

Why screen and tmux Matter

SSH connections drop. Network cables get pulled. Laptops go to sleep. When your connection dies, so does any process running in that terminal — unless you use a multiplexer. screen and tmux decouple your running processes from your terminal window. DodaZIP uses tmux sessions for long-running compression jobs that take hours. Durga Antivirus Pro engineers run system-wide scans inside tmux sessions so they can disconnect and check progress later.

Learning Path

    flowchart LR
  A[Essential Commands] --> B[SSH & Remote Access]
  B --> C[screen & tmux<br/>You are here]
  C --> D[Remote Workflows]
  C --> E[Automation & Scripting]
  style C fill:#f90,color:#fff
  
Prerequisites: SSH access to a remote Linux server and basic command-line skills. Install tmux with apt install tmux or yum install tmux. screen is pre-installed on most distributions.

screen Syntax Overview

screen -S session_name    # Create named session
screen -ls                # List all sessions
screen -r session_name    # Reattach to session
screen -d -r session_name # Detach from elsewhere and reattach
Ctrl+A D                  # Detach from current session

tmux Syntax Overview

tmux new -s session_name  # Create named session
tmux ls                   # List all sessions
tmux attach -t session_name # Attach to session
Ctrl+B D                  # Detach from current session

screen Options Table

OptionDescription
-S nameCreate a new session with a given name
-lsList all screen sessions
-r [name]Reattach to a detached session
-d -r nameDetach a session elsewhere and reattach here
-XSend a command to a running session
-dmS nameStart in detached mode (for scripts)

tmux Options Table

OptionDescription
new -s nameCreate a new named session
lsList all sessions
attach -t nameAttach to a session
kill-session -t nameKill a specific session
new-windowCreate a new window (Ctrl+B c)
split-window -hSplit pane horizontally (Ctrl+B %)
split-window -vSplit pane vertically (Ctrl+B “)
send-keysSend keystrokes to a pane (for scripting)

Examples

Example 1: screen — Create Named Session

$ screen -S mysession
# You're now inside a screen session

# Run a long process
$ rsync -avz /data/ user@backup:/backup/

Press Ctrl+A then D to detach. The rsync continues running.

Example 2: screen — List and Reattach

$ screen -ls
There is a screen on:
        12345.mysession    (Detached)
1 Socket in /run/screen/S-user.

$ screen -r mysession
# Back inside the session — rsync is still running!

List all screen sessions and reattach by name.

Example 3: screen — Detach and Reattach from Another Machine

# On machine A
user@server-a:~$ screen -S deploy-session
user@server-a:~$ ./deploy.sh
# Ctrl+A D to detach

# SSH to server-a from machine B
user@laptop:~$ ssh user@server-a
user@server-a:~$ screen -r deploy-session
# Same session — deploy is still running

Example 4: tmux — Create Named Session

$ tmux new -s dev-session
# Inside tmux now — prefix is Ctrl+B

# Run a process
$ docker compose up

Ctrl+B D detaches. The compose process keeps running.

Example 5: tmux — Split Panes (Ctrl+B % and Ctrl+B “)

Inside a tmux session:

Ctrl+B %   → Split vertically (left/right)
Ctrl+B "   → Split horizontally (top/bottom)
Ctrl+B arrow → Navigate between panes
Ctrl+B x   → Close current pane

Creates a split-pane layout — run htop in one pane, tail -f in another, and a shell in the third.

Example 6: tmux — Attach and List

$ tmux ls
dev-session: 2 windows (created Sat Jun 20 10:00:00 2026)

$ tmux attach -t dev-session
# Back inside the session, all panes intact

Example 7: tmux — Kill a Session

$ tmux kill-session -t dev-session
$ tmux ls
no server running on /tmp/tmux-1000/default

Kill a session from outside. Inside, you can type exit in each shell or use Ctrl+B & to kill the current window.

Example 8: tmux — Scrollback Mode

# Inside tmux, press:
Ctrl+B [          → Enter scrollback mode
Page Up / Page Down → Navigate
Arrow keys        → Line by line
/                 → Search forward
?                 → Search backward
q or Escape       → Exit scrollback mode

Useful for reviewing command output that scrolled off screen.

Example 9: tmux Configuration (~/.tmux.conf)

$ cat ~/.tmux.conf
# Set prefix to Ctrl+A (like screen)
set -g prefix C-a
unbind C-b
bind C-a send-prefix

# Enable mouse support
set -g mouse on

# Increase scrollback buffer
set -g history-limit 50000

# Easy config reload
bind r source-file ~/.tmux.conf \; display "Config reloaded"

# Status bar colors
set -g status-bg blue
set -g status-fg white

After editing, reload with tmux source-file ~/.tmux.conf or Ctrl+B r with the bind above.

Example 10: tmux — Automated Session with Script

#!/bin/bash
# Create a monitoring dashboard session
SESSION="monitor"

tmux new-session -d -s "$SESSION"

# Pane 0: system overview
tmux send-keys -t "$SESSION:0" "htop" Enter

# Split horizontally, pane 1: disk usage
tmux split-window -v -t "$SESSION:0"
tmux send-keys -t "$SESSION:0.1" "watch -d -n 2 df -h" Enter

# Split vertically, pane 2: log monitor
tmux split-window -h -t "$SESSION:0.1"
tmux send-keys -t "$SESSION:0.2" "tail -F /var/log/syslog" Enter

# Select first pane
tmux select-pane -t "$SESSION:0.0"

# Attach
tmux attach -t "$SESSION"

Run this script to instantly create a 3-pane monitoring dashboard.

Common Use Cases

Use Casescreentmux
Named sessionscreen -S nametmux new -s name
DetachCtrl+A DCtrl+B D
Reattachscreen -r nametmux attach -t name
List sessionsscreen -lstmux ls
Split panesLimited (via config)Built-in (% ")
ScrollbackCtrl+A [Ctrl+B [
Kill sessionscreen -X -S name quittmux kill-session -t name

Common Errors

  • screen: Cannot find terminfo entry for ‘xterm-256color’: Run TERM=xterm screen or install ncurses-term.
  • tmux: open terminal failed: missing or unsuitable terminal: Same fix — export TERM=xterm-256color.
  • Lost sessions after reboot: Sessions live in RAM and don’t survive reboot. Use tmux resurrect plugin or save session state.
  • Detached session still running but can’t reattach: Another client is attached to the session. Use screen -d -r name or tmux attach -d -t name.
  • Ctrl+B conflicts with terminal: Change the prefix in ~/.tmux.conf to Ctrl+A (like screen).

Practice Exercises

  1. screen basics: Create a named screen session, run top, detach, and reattach.
  2. tmux panes: Create a tmux session with 3 panes — one for htop, one for tail -f /var/log/syslog, one for a shell.
  3. Session persistence: SSH into a server, start a long-running command inside tmux, disconnect, reconnect, and verify it’s still running.
  4. Scrollback practice: Generate output (like dmesg), use scrollback mode to search for a keyword.
  5. Config customization: Create a ~/.tmux.conf with a custom prefix and status bar.

Challenge

Create a tmux launcher script for server diagnostics that opens four panes:

  1. htop (process monitoring)
  2. tail -F /var/log/syslog (live log)
  3. watch -d -n 2 'ss -tan' (network connections)
  4. watch -d -n 5 df -h (disk usage)

Durga Antivirus Pro uses a similar session layout during incident response investigations.

#!/bin/bash
SESSION="diagnostics"

tmux new-session -d -s "$SESSION" -n "monitor"
tmux send-keys -t "$SESSION" "htop" Enter

tmux split-window -h -t "$SESSION"
tmux send-keys -t "$SESSION" "watch -d -n 2 'ss -tan | head -20'" Enter

tmux split-window -v -t "$SESSION"
tmux send-keys -t "$SESSION" "tail -F /var/log/syslog" Enter

tmux select-pane -t "$SESSION:0.0"
tmux split-window -v -t "$SESSION"
tmux send-keys -t "$SESSION" "watch -d -n 5 df -h" Enter

tmux select-pane -t "$SESSION:0.0"
tmux attach -t "$SESSION"

Real-World Task

Your team needs to run a 6-hour database migration on a production server. Set up a tmux or screen session so:

  1. The migration runs inside a named session
  2. The team can check progress by attaching
  3. Panes show migration log, database status, and a shell
  4. Everyone knows how to detach without stopping the migration

What is screen?

screen is a terminal multiplexer that allows multiple shell sessions within one terminal, with detach/reattach capabilities — oldestablished and available on nearly every Unix system.

What is tmux?

tmux (terminal multiplexer) is a modern alternative to screen with built-in pane splitting, scriptable control, configurable status bars, and an active plugin ecosystem.

Related Tutorials

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro