tmux-Cheat-Sheet

Managing several terminal tasks at once can be difficult, especially when you’re connected to a remote Linux server via SSH. tmux helps organize these tasks by letting you run multiple terminal sessions, windows, and panes from a single terminal.

One useful feature of tmux is that a session can continue running even after you disconnect from the server. You can reconnect later and continue working from where you left off.

This cheat sheet covers the most useful tmux commands and keyboard shortcuts for managing sessions, windows, panes, copied text, and configuration.

What is tmux?

tmux is a terminal multiplexer available on Linux systems. It allows you to run several terminal environments inside one terminal window and organize them according to your work.

For example, you can use one pane to run a command, another to watch server logs, and another to edit or test a script. You can also create separate windows for different tasks within the same session.

tmux is especially useful when working with remote servers over SSH. If you detach from a tmux session, the processes running inside it can continue. You can reconnect to the server later and attach to the same session.

The three main parts of tmux are:

  • Sessions: Hold related windows and provide the main workspace for a task.
  • Windows: Separate different activities inside a session.
  • Panes: Divide a window into multiple terminal areas.

Most Linux distributions include tmux in their package repositories. If it is not already installed, install it using your distribution’s package manager.

tmux Commands

You can manage tmux directly from the command line or use keyboard shortcuts after starting a session.

The default tmux prefix key is CTRL+b. For shortcuts, press CTRL+b first, release both keys, and then press the required shortcut key.

tmux Sessions

A tmux session provides the main workspace where you can create and manage windows and panes. You can name sessions to keep different projects or tasks organized.

Command Description
tmux Start a new tmux session.
tmux new -s [session_name] Create a new session with a specified name.
tmux attach Reattach to the most recently active session.
tmux detach Detach from the current session while keeping it running.
tmux attach -t [session_name] or tmux a -t [session_name] Attach to a specific session.
tmux switch -t [session_name] Switch to another session.
tmux rename-session -t [old_name] [new_name] Rename an existing session.
tmux list-sessions or tmux ls Display active tmux sessions.
tmux kill-session -t [session_name] Close a specific session.
tmux kill-session -a Close all sessions except the current session.
tmux kill-session -a -t [session_name] Close all sessions except the specified session.
tmux kill-server Stop the tmux server and close all its sessions.

For example, create a session named project with:

tmux new -s project

You can later return to it with:

tmux attach -t project

tmux Windows

A window is a separate workspace inside a tmux session. Windows are useful when you want to keep different tasks apart without creating separate tmux sessions.

Command / Shortcut Action
CTRL+b then c Create a new window.
CTRL+b then , Rename the current window.
CTRL+b then w Display the available windows.
CTRL+b then & Close the current window.
CTRL+b then n Move to the next window.
CTRL+b then p Move to the previous window.
CTRL+b then l Return to the previously active window.
CTRL+b then 0...9 Open a window by its number.
CTRL+b then d Detach from the current tmux session.
tmux select-window -t [window_name] Select a window using its index or name.
tmux rename-window [new_name] Rename the current window.

For example, you could keep server monitoring in one window and application testing in another. Switching between them does not require creating another SSH connection.

tmux Panes

Panes divide a tmux window into multiple terminal sections. This lets you keep several commands visible at the same time.

Command / Shortcut Action
CTRL+b then % Split the current pane vertically.
CTRL+b then " Split the current pane horizontally.
CTRL+b then x Close the current pane.
CTRL+b then o Move to the next pane.
CTRL+b then z Toggle the current pane between normal and full-screen view.
CTRL+b then ; Switch between the two most recently active panes.
CTRL+b then { Move the current pane to the left.
CTRL+b then } Move the current pane to the right.
CTRL+b then SPACE Cycle through available pane layouts.
CTRL+b then ! Move the current pane into a separate window.
exitorCTRL+d Close the active pane.
CTRL+b then q Display pane numbers.

You can also resize panes when the default size is not suitable.

Press:

CTRL+b then :

This opens tmux command mode. You can then use commands such as:

resize-pane -D
resize-pane -U
resize-pane -R
resize-pane -L

These move the shared pane boundary down, up, right, or left.

You can also specify the number of cells:

resize-pane -U 10

This moves the pane boundary upward by 10 cells.

To maximize the active pane, use:

resize-pane -Z

Run the same command again to return the pane to its previous layout.

You can also adjust pane dimensions with arrow-key shortcuts:

Shortcut Action
CTRL+b then Up Arrow Increase pane height.
CTRL+b then Down Arrow Decrease pane height.
CTRL+b then Left Arrow Increase pane width.
CTRL+b then Right Arrow Decrease pane width.

Pane resizing works along the boundaries shared by neighboring panes. Changing one boundary can therefore change the size of the adjacent pane as well.

tmux Copy Mode

Copy Mode allows you to move through previous terminal output, select text, and copy it without relying on the terminal’s normal scrolling behavior. This is particularly useful when a command produces a large amount of output, and you need to retrieve a specific line or section.

Command / Shortcut Action
CTRL+b then [ Enter Copy Mode.
q Leave Copy Mode.
SPACE Start selecting text.
ENTER Copy the selected text.
ESC Clear the selection and leave Copy Mode.
CTRL+b then ] Paste copied text.
h Move left.
j Move down.
k Move up.
l Move right.
w Move forward by one word.
b Move backward by one word.
CTRL+u Scroll up by half a page.
CTRL+d Scroll down by half a page.
PgUp Scroll up by a full page.
PgDn Scroll down by a full page.

For example, if a log command has produced several screens of output, press CTRL+b followed by [ to enter Copy Mode. Navigate to the required text, press SPACE to begin selecting, and press ENTER when the selection is complete.

tmux Configuration

tmux can be customized through its tmux.conf configuration file. You can change keyboard shortcuts, window and pane numbering, status bar settings, and other behavior.

For system-wide settings, edit:

sudo nano /etc/tmux.conf

For settings that apply only to your user account, edit:

nano ~/.tmux.conf

Some useful configuration examples include:

Configuration Description
set-option -g prefix C-a Changes the tmux prefix from CTRL+b to CTRL+a.
unbind C-b Removes the default CTRL+b binding.
bind C-a send-prefix Assigns CTRL+a as the new prefix.
unbind % Removes the default vertical split shortcut.
bind h split-window -h Assigns a custom shortcut for a horizontal split.
unbind '"' Removes the default horizontal split shortcut.
bind v split-window -v Assigns a custom shortcut for a vertical split.
setw -g monitor-activity on Enables activity monitoring for windows.
setw -g visual-activity on Shows a visual notification when activity occurs.
set -g base-index 1 Starts window numbering from 1 instead of 0.
set -g pane-base-index 1 Starts pane numbering from 1 instead of 0.

After modifying the configuration file, save the changes and exit the editor.

Configuration changes may not appear in an already running tmux session. Restart the relevant tmux session for the updated settings to take effect.

tmux Cheat Sheet

The following compact reference covers the commands and shortcuts most commonly used when working with tmux.

Session Commands
Command Purpose
tmux Start tmux
tmux new -s name Create named session
tmux ls List sessions
tmux attach -t name Attach to a session
tmux switch -t name Switch sessions
tmux rename-session -t old new Rename session
tmux kill-session -t name Close a session
tmux kill-server Close all tmux sessions
Window Shortcuts
Shortcut Purpose
CTRL+b c New window
CTRL+b , Rename window
CTRL+b w List windows
CTRL+b n Next window
CTRL+b p Previous window
CTRL+b l Last active window
CTRL+b 0...9 Select window by number
CTRL+b & Close window
CTRL+b d Detach session
Pane Shortcuts
Shortcut Purpose
CTRL+b % Vertical split
CTRL+b " Horizontal split
CTRL+b o Next pane
CTRL+b z Zoom pane
CTRL+b ; Previous active pane
CTRL+b { Move pane left
CTRL+b } Move pane right
CTRL+b SPACE Change pane layout
CTRL+b ! Move pane to a new window
CTRL+b q Show pane numbers
CTRL+b x Close pane
Copy Mode Shortcuts
Shortcut Purpose
CTRL+b [ Enter Copy Mode
SPACE Start selection
ENTER Copy selection
CTRL+b ] Paste selection
q Exit Copy Mode
h / j / k / l Move around the output
PgUp / PgDn Scroll by page

Keep this section as a quick reference when working with tmux on Linux or managing long-running tasks over SSH.

Conclusion

tmux provides a practical way to keep multiple terminal tasks organized in one environment. Sessions help separate projects, windows keep activities grouped, and panes allow several commands to remain visible at the same time.

The detach and reattach features are particularly useful for remote server administration because a running session can remain active while your SSH connection is closed. With a few common shortcuts and basic configuration changes, tmux can become a useful part of a Linux server workflow.

Find more knowldge base about Windows CMD Commands Cheat Sheet

Popular Posts You May Read

Explore more hosting insights, tips and industry updates.

VPS : Multiple Domain Hosting

There are multiple reasons why someone would want to have multiple domain hosting. For example,…

What is a URL Redirect and How does it Function

What is a URL Redirect and How does it Function

In this article, you will discover what is a URL redirect and how it works.…

SSL FAQs – Why Choose GlobalSign?

GlobalSign is seen as one of the world’s first providers of SSL certificates, having been…