tmux Cheat Sheet: Commands and Shortcuts Explained

September 26, 2024

Introduction

The tmux utility in Linux allows you to run and manage multiple processes within a single terminal session. You can create multiple sessions, split windows into panes, or detach from a session and reattach later without disrupting a running process.

Learn the essential tmux commands and download our handy cheat sheet for quick reference.

Tmux command cheat sheet for managing sessions, panes, and windows.

Prerequisites

What is tmux?

tmux is a terminal multiplexer in Linux. It is a popular utility for system administrators as it allows them to open and manage several terminal sessions in one terminal window.

The tool works on all Linux distributions and is useful for managing long-running tasks over SSH. Users can detach from a session on one computer, switch to a second computer, reconnect to the server, and reattach to the same session without losing work.

Note: tmux comes pre-installed on most Linux distributions. If you don't have tmux installed, check out our guide on how to install tmux on Linux.

You can use tmux panes, windows, and sessions to organize tasks logically:

  • Sessions. Use sessions to control an overall task from a unified interface. For example, you can keep all test-related activities within a single session.
  • Windows. Launch specific activities or projects in separate windows within a session.
  • Panes. Use panes to split a window into multiple views. For instance, you can work on a script in one pane while monitoring logs in another.
An example of a tmux session with multiple windows.

Note: tmux command usage may differ from version to version. Your tmux version may not support all the commands listed below. For more information, see the official tmux changelog.

tmux Commands

Use tmux commands in the terminal to launch sessions and manage windows and panes. However, managing multiple panes through direct CLI commands can be inefficient.

You can control tmux using keyboard shortcuts. Keyboard shortcuts are a user-friendly way to navigate, manage content, and control the layout once a session is launched. CTRL+b is the default prefix key and must be followed by a specific hotkey to perform an action.

tmux Sessions

A tmux session is the primary environment for managing windows and panes. A session groups related tasks or projects in a unified workspace. The following table lists essential commands for managing sessions:

CommandDescription
tmuxStart a new session.
tmux new -s [session_name]Create a new session with a specific name. Replace session_name with the actual name of the session.
tmux attachRe-attach to the latest active session.
tmux detachDisconnect from a session, but keep it running.
tmux attach -t [session_name] or
tmux a -t [session_name]
Attach to session with a specific name. Replace session_name with the actual name of your session.
tmux switch -t [session_name]Switch to a different session.
tmux rename-session -t [old_name] [new_name]Rename an existing session.
tmux list-sessions or
tmux ls
List all active tmux sessions.
tmux kill-session -t [session_name]Terminate a specific session.
tmux kill-session -aKill all sessions but the current one.
tmux kill-session -a -t [session_name]Terminate all sessions except the specified one.
tmux kill-serverTerminate the tmux server, ending all sessions, windows, and panes.

tmux Windows

Windows are used to separate individual tasks within a session and create a manageable window-based interface. The table lists commands for managing windows within tmux sessions:

Command/ShortcutAction
CTRL+b then cCreate a new window.
CTRL+b then ,Rename the current window.
CTRL+b then wList all windows.
CTRL+b then &Kill the current window.
CTRL+b then nSwitch to the next window.
CTRL+b then pSwitch to the previous window.
CTRL+b then lOpen the last window.
CTRL+b then 0....9Switch to a specific numbered window.
CTRL+b then dDetach from the current session.
tmux select-window -t [window_name]Select a specific window by its index or name.
tmux rename-window [new_name]Rename the current window.

tmux Panes

A pane is a basic element of a tmux window within a session. Managing many panes simultaneously can quickly clutter a window if not organized properly. The following shortcuts help you manage and organize panes efficiently:

Command/ShortcutAction
CTRL+b then %Split the current pane vertically.
CTRL+b then "Split the current pane horizontally.
CRTL+b then xClose the current pane.
CTRL+b then oSwitch between panes.
CTRL+b then zToggle pane zoom (make pane full screen).
CTRL+b then ;Toggle between the last two active panes.
CTRL+b then {Move the current pane left.
CTRL+b then }Move the current pane right.
CTRL+b then SPACEToggle through different pane layouts.
CTRL+b then !Convert the current pane into a window.
exit or
CTRL+d
Close the selected pane.
CTRL+b then qDisplay pane number.
CTRL+b then :Enter command mode. The bottom bar will change from green to yellow. Now you can type a command to resize the pane:
resize-pane -D - Move the boundary line for the pane downward.
resize-pane -U - Move the boundary line for the pane upward.
resize-pane -R - Move the boundary line for the pane right.
resize-pane -L - Push the boundary line for the pane left.
resize-pane -U 10 - Move the boundary line up 10 cells.
resize-pane –t 2 --R 5 - Move the boundary line of cell number 2 five cells to the right.
resize-pane -Z - Maximize the pane to full screen. Use the same command to set it back to normal.
CTRL+b+[up_arrow]Increase pane height.
CTRL+b+[down_arrow]Decrease pane height.
CTRL+b+[left_arrow]Increase pane width.
CTRL+b+[right_arrow]Decrease pane width.

Note: Resizing only works along shared boundaries between panes. You can't resize a pane if it's already at the edge of the screen. Also, adjusting a shared boundary affects adjacent panes. For example, resizing the top boundary of one pane will change the size of the pane below it.

tmux Copy Mode

Copy Mode allows users to navigate through the output of a pane and select and copy text. This feature is indispensable in terminal sessions with a lot of output. You can manipulate pane content and transfer it between panes, windows, and sessions much more efficiently.

The following table lists the most useful Copy Mode commands:

Command/ShortcutAction
CTRL+b then [Enter copy mode.
qExit copy mode.
SPACEStart text selection in copy mode.
ENTERCopy the selected text.
ESCClear the selected text and exit the copy mode.
CTRL+b then ]Paste the copied text.
hMove the cursor left.
jMove the cursor down.
kMove the cursor up.
lMove the cursor right.
wMove the cursor one word forward.
bMove the cursor one word backward.
CTRL+uScroll up half a page.
CTRL+dScroll down half a page.
PgUpScroll up full page.
PgDnScroll down full page.

tmux Configuration

tmux is highly configurable and enables users to customize key bindings, window management, and visual aspects like status bars and panes. Тhe tmux configuration file, tmux.conf, allows you to make system-wide or user-specific changes.

To apply changes for all users, use a text editor, like Nano, to create or edit the file in the system directory:

sudo nano /etc/tmux.conf

To apply changes for a single user, create or edit the file in the user’s home directory:

sudo nano ~/.tmux.conf

Once the tmux.conf file is created, add custom commands and remap function keys. The following table contains common configuration examples and their descriptions:

CommandDescription
set-option -g prefix C-a
unbind C-b
bind C-a send-prefix
Changes the default CTRL+b binding to CTRL+a to activate functions.
unbind %
bind h split-window –h
Remaps the horizontal split to CTRL+b+h.
unbind '"'
bind v split-window –v
Remaps the vertical split key to CTRL+b+v.
set -g status-bg blue
set -g status-fg black
Changes the color of the status bar (background to blue and foreground to black). You can also use a numerical code (0 – 255) to specify a color.
setw -g monitor-activity on
setw -g visual-activity on
Enables visual notifications for activity in windows.
set -g base-index 1Starts window numbering at 1 instead of 0.
set -g pane-base-index 1Starts pane numbering at 1 instead of 0.

After making changes, save the file and exit the editor. If you have any active tmux sessions, the changes take effect until they are closed and restarted. Detaching and reattaching a session will not apply the new settings.

tmux Cheat Sheet

Download the tmux Commands Cheat Sheet in PDF format. Use this one-page reference sheet to access essential tmux commands whenever you need them.

Tmux commands cheat sheet image.

Conclusion

The listed tmux commands and downloadable cheat sheet enable you to manage multiple sessions, panes, and windows more efficiently. Additionally, you can customize tmux to fit your workflow, giving you even greater control over the terminal environment.

Next, read this ultimate list of Linux commands all users should know.

Was this article helpful?
YesNo
Vladimir Kaplarevic
Vladimir is a resident Tech Writer at phoenixNAP. He has more than 7 years of experience in implementing e-commerce and online payment solutions with various global IT services providers. His articles aim to instill a passion for innovative technologies in others by providing practical advice and using an engaging writing style.
Next you should read
Linux Network Commands Cheat Sheet
September 13, 2023

Master Linux networking commands! This article provides an overview of 20 Linux network commands, and features a free downloadable PDF cheat sheet.
Read more
How To Install and Use Linux Screen, With Commands
April 7, 2022

Screen is a powerful tool for working in the command line. It lets you create, monitor, and switch between several different windows.
Read more
How to Connect to a Remote Server via SSH from Windows, Linux or Mac
November 23, 2023

In this tutorial, find out How To Use SSH to Connect to a Remote Server in Linux, Mac, or Windows.
Read more
25 Common SSH Commands in Linux With Examples
September 5, 2024

This guide covers practical SSH commands such as specifying a username for your connection, using a different port number, generating SSH key pairs, and much more.
Read more