Tmux Cheat Sheet: Essential Commands And Quick References

Tmux Cheat Sheet

Running parallel processes on a graphical user interface (GUI) usually requires tabbed terminals. But what if you could only work with command-line interfaces (CLI)? The answer is Tmux, which is short for “terminal multiplexer.”

Better still, in Tmux, you can detach from a session without losing its state and later return to it by re-attaching it. This hands-free functionality is helpful when you, say, need to make multiple SSH connections because, by default, an SSH session occupies the entire CLI, hindering you from working on other tasks in tandem.

A PDF download of this cheat sheet is available here.

Tmux Cheat Sheet Search

Search our Tmux cheat sheet to find the right cheat for the term you're looking for. Simply enter the term in the search bar and you'll receive the matching cheats available.

Install Tmux

Tmux is available for Linux and macOS. As for Windows, you can run Tmux via the Linux Subsystem feature by following the procedures here if you’re using Windows 10 build 14361 or above. This article assumes you are using either Linux or macOS.

CommandDescription
# Homebrew
brew install tmux
Install on macOS
# Ubuntu / Debian *
sudo apt-get update
sudo apt-get install tmux
# Fedora
sudo
dnf -y install tmux
# CentOS
sudo
yum -y install tmux
Install on Linux
(*Depending on Linux distribution, you may need to replace apt-get with apt.)

Tmux Terms

Familiarize yourself with them as they often appear in Tmux-related discussions.

TermDescription
PaneAn open command prompt (known as “pseudo-terminal”), which may occupy the entire screen or appear horizontally/vertically stacked
WindowA single/split view of open panes occupying the screen:

Split windows
SessionA single collection of pseudo-terminals under the management of Tmux. Once you kill the last session, Tmux exits. Each session is persistent and will survive accidental disconnection (such as SSH connection timeout) or intentional detaching by the user.
In the example above, the session comprises panes 0:bash, 1:bash, and 2:bash. The current pane is 2:bash, marked by an asterisk *. Here, the cursor is active, and you can type into the pane. The other pane in the same window is 1:bash, marked by a hyphen -.
ClientThe background process displaying your session
ServerA single server manages all open sessions. Servers and clients are separate processes that communicate through a socket in /tmp.

Tmux Commands

You may run Tmux commands by name from the CLI, such as tmux starts a new session. When you start Tmux, it creates a new single-window session and displays it on the screen.

A status line at the bottom shows current session information and is used to enter interactive commands prefixed by the trigger key combination Ctrl+b (Linux) or control+b (macOS). This trigger tells Tmux to watch out for keystrokes of interest.

Ctrl+b alone applies to short commands of one or two keys. Ctrl+b followed by the colon character (:) brings up a prompt for you to issue specific commands, after which you press Enter for execution.

Tmux Shortcuts

Run the following from the CLI:

CommandDescription
tmuxLaunch Tmux
tmux -VCheck Tmux version
tmux list-keys | lessList all commands
tmux lsShow all sessions
tmux infoShow every session, window, and pane
tmux a(Re)attach to the most recently created session
man tmuxDisplay full manual of Tmux

Run these commands inside a Tmux session:

CommandDescription
qAfter execution of a command yields a display, close the display. For example, Ctrl+b+? brings up a list, and a single q keypress closes the list.
Ctrl+b
<command>
Send <command> to Tmux instead of shell CLI. For each of the following items, replace <command> with the given key.
Ctrl+lClear console contents (the “l” is “L” in small caps)
General
<command>
?
:list-keys
List all commands
:Enter command mode (display prompt for detailed Tmux commands)
tShow computer time
Windows
<command>
cCreate new window
,Rename current window
pNavigate to previous window
nNavigate to next window
wList windows (which you may select and expand / collapse with arrow keys)
Panes
<command>
%Split vertically
"Split horizontally
(right arrow key)Switch to right pane
(left arrow key)Switch to left pane
(up arrow key)Switch to upper pane
(down arrow key)Switch to lower pane
Sessions
<command>
dDetach from session

Scroll down for specific commands in detail.

Tmux Sessions

Create new session

CommandDescription
tmux
tmux new
tmux new-session
Create new session from CLI
Ctrl+b :newCreate new session from inside Tmux
tmux new -s sess0Create new session named sess0
Ctrl+b :new sess0Create new session sess0 from inside Tmux

List all sessions

CommandDescription
tmux ls
tmux list-sessions
Show all sessions
Ctrl+b sShow all sessions from inside Tmux

Operations on sessions

CommandDescription
tmux a
tmux at
tmux attach
tmux attach-session
Attach to the most recently created session
tmux a -t s0Attach to session s0
Ctrl+b <command>
Rename session
Detach from session
Session and window preview
Move to previous session
Move to next session

Terminate (kill) sessions

CommandDescription
tmux kill-ses
tmux kill-session
Kill last active session
tmux kill-ses -t s0Kill session named s0
tmux kill-ses -aKill all sessions except the current one
tmux kill-ses -a -t s0Kill all sessions except s0

Tmux Windows

CommandDescription
tmux new -s s1 -n w2Create new session s1 and window w2
Ctrl+b <command>
cCreate new window
,Rename active window
&Close active window (Tmux may prompt you to confirm your action with y/n)
pNavigate to previous window
nNavigate to next window
wList windows (which you may select and expand / collapse with arrow keys)
:swapw -s 0 -t 2Swap windows 0 and 2(swapw is short for swap-window)
:swapw -t -1Move active window to the left by one position

Tmux Command Generator

Say goodbye to the hassle of trying to remember the exact syntax for your Tmux commands! With our Tmux Command Generator, you can simply say what you need Tmux to do, and we will generate the command for you.

Tmux Panes

CommandDescription
Ctrl+b <command>
qShow pane numbers:

Numbered panes in Tmux
q 0 … 9Switch to pane by number
oGo to next pane
zZoom in/out of pane
!Convert pane into new window
%Split vertically
"Split horizontally
Switch to right pane
Switch to left pane
Switch to upper pane
Switch to lower pane
;Toggle last active pane
[spacebar]Toggle between pane layouts
{Move current pane leftward
}Move current pane rightward
xClose current pane
:setw synchronize-panesToggle synchronize-panes (the ability to send the same command to all panes at once)

Synchronize panes
:resize-pane -L 5Move the boundary of the pane leftwards by 5 lines.
Direction flags:
-U upwards
-D downwards
-L leftwards
-R rightwards
M #
M: meta key; ALT for Linux, ESC for macOS#: 1, 2, 3, 4, 5
Splitting panes in a designated form:
#=1: uniform vertical split
#=2: uniform horizontal split
#=3: horizontal split, main pane on top, others on bottom, vertically split, all same width
#=4: vertical split, main pane left, others right, horizontally split, all same height
#=5: tile, new panes on bottom, same height before same width

Tmux Copy Mode

You can copy and paste text content in Tmux under Copy Mode. The buffer in Tmux is its clipboard and buffer_0, buffer_1, etc. correspond to clipboard items copied from a Tmux session.

CommandDescription
Ctrl+b :setw -g mode-keys viUse vi keys in the buffer (vi: vim editor)
Ctrl+b [Enter copy mode
Scroll up
Scroll down
qQuit copy mode
0Go to beginning of line
$Go to end of line
gGo to first line
GGo to last line
hMove cursor left
jMove cursor down
kMove cursor up
lMove cursor right
bTraverse text content backward, cursor on first character of each word
eTraverse text content forward, cursor on last character of each word
wTraverse text content one word at a time
/Search forward
?Search backward
nNext keyword occurrence
NPrevious keyword occurrence
[Spacebar]Begin selection
[Enter]Copy selection
ESCClear selection
Ctrl+b ]Paste selection
Ctrl+b :show-bufferDisplay buffer_0 contents
Ctrl+b :capture-paneCopy whole visible contents of the pane to a buffer
Ctrl+b :list-buffersShow all buffers
Ctrl+b :choose-bufferShow all buffers and paste selected
Ctrl+b :save-buffer buf.txtSave buffer contents to buf.txt
Ctrl+b :delete-buffer -b 1Delete buffer_1

Tmux Configuration

You can configure Tmux via the ~/.tmux.conf file. If it doesn’t exist, create it:

$ touch ~/.tmux.conf

To reload Tmux with the new settings:

$ tmux source-file ~/.tmux.conf

Custom Keystrokes

Add these commands to ~/.tmux.conf to modify Tmux function keys. Each command spans two lines. The unbind command deactivates the default key combination.

CommandDescription
unbind '"'
bind - split-window -v
Change key combination to split window into two horizontal panes: Replace default Ctrl+b " with Ctrl+b – (hyphen) 
unbind %
bind | split-window -h
Change key combination to split window into two vertical panes: Replace default Ctrl+b % with Ctrl+b | (pipe) 
unbind C-b
set -g prefix C-a
Replace trigger key combination Ctrl+b with Ctrl+a

Making Tmux Copy Mode to default to vi keys

CommandDescription
setw -g mode-keys viUse vi keys in the buffer

Customization

The following commands are for customizing the status bar at the bottom of a Tmux window:

CommandDescription
set -g status-justify [left|centre|right]Aligns the names of Tmux windows left/center/right
set -g status-left '...'Replaces name of current session with ‘...’  in status bar
setw -g
window-status-format
`#[fg=white,bg=black]#I`
Formats the window names as follows:
Formatted status bar
Default window formatting:
Default status bar
Variables:
#I: window index
#S: session name
#W: window name

For detailed formatting instructions: man tmux > /STYLES > keep pressing “n” key until you reach the section titled “STYLES”.

To reset Tmux to default settings, delete all lines in ~/.tmux.conf and run tmux kill-server. Close any running CLI terminals, reopen the terminal and start Tmux again.

Frequently Asked Questions

Level Up in Cyber Security: Join Our Membership Today!

vip cta image
vip cta details
  • Cassandra Lee

    Cassandra is a writer, artist, musician, and technologist who makes connections across disciplines: cyber security, writing/journalism, art/design, music, mathematics, technology, education, psychology, and more. She's been a vocal advocate for girls and women in STEM since the 2010s, having written for Huffington Post, International Mathematical Olympiad 2016, and Ada Lovelace Day, and she's honored to join StationX. You can find Cassandra on LinkedIn and Linktree.

>

StationX Accelerator Pro

Enter your name and email below, and we’ll swiftly get you all the exciting details about our exclusive StationX Accelerator Pro Program. Stay tuned for more!

StationX Accelerator Premium

Enter your name and email below, and we’ll swiftly get you all the exciting details about our exclusive StationX Accelerator Premium Program. Stay tuned for more!

StationX Master's Program

Enter your name and email below, and we’ll swiftly get you all the exciting details about our exclusive StationX Master’s Program. Stay tuned for more!