Operations 15 min read

Master tmux: Keep Long‑Running Scripts Alive on Remote Servers

This guide explains how to use tmux—a terminal multiplexer—to create, detach, reattach, and manage sessions, windows, and panes on Linux servers, ensuring scripts continue running even when SSH connections drop or terminals close.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Master tmux: Keep Long‑Running Scripts Alive on Remote Servers

What is tmux?

tmux is a terminal multiplexer that lets you create, access, and control multiple terminal sessions within a single window. Each session can contain several windows, and each window can be split into independent panes. Because tmux separates the session from the terminal window, the session keeps running in the background even if the window is closed.

Installation

sudo yum install tmux

Basic Concepts

A session groups one or more windows; a window occupies the full screen and can contain multiple panes . Sessions, windows, and panes are independent and can be switched at any time.

Prefix Key

All tmux shortcuts start with the prefix Ctrl+B. After pressing the prefix, the next key triggers the desired command (e.g., Ctrl+B d detaches the session).

Session Operations

Create a session : tmux new -s <session-name> List sessions : tmux ls Detach : Ctrl+B d or tmux detach Attach : tmux attach -t <session-name|ID> Switch : tmux switch -t <session-name|ID> Rename : tmux rename -t <old-name|ID> <new-name|ID> Kill a session : tmux kill-session -t <session-name|ID> Kill all sessions :

tmux kill-server
[root@ecs-centos-7 ~]# tmux new -s dev
[root@ecs-centos-7 ~]# tmux ls
dev: 1 windows (created Sun Sep 20 23:26:33 2020) [134x34] (attached)

Window Operations

Create a window : tmux new-window or Ctrl+B c List windows : tmux list-window Switch windows : Ctrl+B p (previous), Ctrl+B n (next), Ctrl+B l (last), Ctrl+B w (choose)

Kill a window : tmux kill-window or

tmux kill-window -t <window-ID>
[root@ecs-centos-7 ~]# tmux list-window
0: root@ecs-centos-7:~* (1 panes) [134x34] @1 (active)
1: root@ecs-centos-7:~ (1 panes) [134x34] @8

Pane Operations

Split pane vertically : tmux split-window Split pane horizontally : tmux split-window -h Select pane : tmux select-pane -U/D/L/R or Ctrl+B <arrow> Swap panes : tmux swap-pane -U/D or Ctrl+B { / Ctrl+B } Kill pane : tmux kill-pane or tmux kill-pane -t <pane-ID> or

Ctrl+B x
# Split vertically
$ tmux split-window
# Split the lower pane horizontally
$ tmux split-window -h
# Swap the two panes
$ tmux swap-pane -U

Quick Reference

Use tmux list-commands to see all commands and tmux list-keys for all key bindings.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

OperationsLinuxSession Managementterminal multiplexertmuxremote scripting
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.