screen and tmux Commands in Linux — Terminal Multiplexers
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
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 sessiontmux 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 sessionscreen Options Table
| Option | Description |
|---|---|
-S name | Create a new session with a given name |
-ls | List all screen sessions |
-r [name] | Reattach to a detached session |
-d -r name | Detach a session elsewhere and reattach here |
-X | Send a command to a running session |
-dmS name | Start in detached mode (for scripts) |
tmux Options Table
| Option | Description |
|---|---|
new -s name | Create a new named session |
ls | List all sessions |
attach -t name | Attach to a session |
kill-session -t name | Kill a specific session |
new-window | Create a new window (Ctrl+B c) |
split-window -h | Split pane horizontally (Ctrl+B %) |
split-window -v | Split pane vertically (Ctrl+B “) |
send-keys | Send 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 runningExample 4: tmux — Create Named Session
$ tmux new -s dev-session
# Inside tmux now — prefix is Ctrl+B
# Run a process
$ docker compose upCtrl+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 paneCreates 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 intactExample 7: tmux — Kill a Session
$ tmux kill-session -t dev-session
$ tmux ls
no server running on /tmp/tmux-1000/defaultKill 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 modeUseful 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 whiteAfter 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 Case | screen | tmux |
|---|---|---|
| Named session | screen -S name | tmux new -s name |
| Detach | Ctrl+A D | Ctrl+B D |
| Reattach | screen -r name | tmux attach -t name |
| List sessions | screen -ls | tmux ls |
| Split panes | Limited (via config) | Built-in (% ") |
| Scrollback | Ctrl+A [ | Ctrl+B [ |
| Kill session | screen -X -S name quit | tmux kill-session -t name |
Common Errors
- screen: Cannot find terminfo entry for ‘xterm-256color’: Run
TERM=xterm screenor installncurses-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 resurrectplugin or save session state. - Detached session still running but can’t reattach: Another client is attached to the session. Use
screen -d -r nameortmux attach -d -t name. - Ctrl+B conflicts with terminal: Change the prefix in
~/.tmux.conftoCtrl+A(like screen).
Practice Exercises
- screen basics: Create a named screen session, run
top, detach, and reattach. - tmux panes: Create a tmux session with 3 panes — one for
htop, one fortail -f /var/log/syslog, one for a shell. - Session persistence: SSH into a server, start a long-running command inside tmux, disconnect, reconnect, and verify it’s still running.
- Scrollback practice: Generate output (like
dmesg), use scrollback mode to search for a keyword. - Config customization: Create a
~/.tmux.confwith a custom prefix and status bar.
Challenge
Create a tmux launcher script for server diagnostics that opens four panes:
htop(process monitoring)tail -F /var/log/syslog(live log)watch -d -n 2 'ss -tan'(network connections)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:
- The migration runs inside a named session
- The team can check progress by attaching
- Panes show migration log, database status, and a shell
- 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
- Essential Linux Commands — remote access tools
- Linux Administration Basics — foundational administration
- Bash Scripting Guide — automate tmux with scripts
- Cron Job Scheduling — schedule checks to verify session status
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro