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.
Command | Description |
---|---|
# 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.
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.
Other Links You Might Like:
Tmux Shortcuts
Run the following from the CLI:
Command | Description |
---|---|
tmux | Launch Tmux |
tmux -V | Check Tmux version |
tmux list-keys | less | List all commands |
tmux ls | Show all sessions |
tmux info | Show every session, window, and pane |
tmux a | (Re)attach to the most recently created session |
man tmux | Display full manual of Tmux |
Run these commands inside a Tmux session:
Command | Description |
---|---|
q | After 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+l | Clear 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) |
t | Show computer time |
Windows<command> | |
c | Create new window |
, | Rename current window |
p | Navigate to previous window |
n | Navigate to next window |
w | List 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> | |
d | Detach from session |
Scroll down for specific commands in detail.
Tmux Sessions
Create new session
Command | Description |
---|---|
tmux tmux new tmux new-session | Create new session from CLI |
Ctrl+b :new | Create new session from inside Tmux |
tmux new -s sess0 | Create new session named sess0 |
Ctrl+b :new sess0 | Create new session sess0 from inside Tmux |
List all sessions
Command | Description |
---|---|
tmux ls tmux list-sessions | Show all sessions |
Ctrl+b s | Show all sessions from inside Tmux |
Operations on sessions
Command | Description |
---|---|
tmux a tmux at tmux attach tmux attach-session | Attach to the most recently created session |
tmux a -t s0 | Attach to session s0 |
Ctrl+b <command> | |
$ | Rename session |
d | Detach from session |
w | Session and window preview |
( | Move to previous session |
) | Move to next session |
Terminate (kill) sessions
Command | Description |
---|---|
tmux kill-ses tmux kill-session | Kill last active session |
tmux kill-ses -t s0 | Kill session named s0 |
tmux kill-ses -a | Kill all sessions except the current one |
tmux kill-ses -a -t s0 | Kill all sessions except s0 |
OTHER CHEAT SHEETS YOU MAY LIKE:
Tmux Windows
Command | Description |
---|---|
tmux new -s s1 -n w2 | Create new session s1 and window w2 |
Ctrl+b <command> | |
c | Create new window |
, | Rename active window |
& | Close active window (Tmux may prompt you to confirm your action with y/n ) |
p | Navigate to previous window |
n | Navigate to next window |
w | List windows (which you may select and expand / collapse with arrow keys) |
:swapw -s 0 -t 2 | Swap windows 0 and 2(swapw is short for swap-window) |
:swapw -t -1 | Move 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
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.
Command | Description |
---|---|
Ctrl+b :setw -g mode-keys vi | Use vi keys in the buffer (vi: vim editor) |
Ctrl+b [ | Enter copy mode |
↑ | Scroll up |
↓ | Scroll down |
q | Quit copy mode |
0 | Go to beginning of line |
$ | Go to end of line |
g | Go to first line |
G | Go to last line |
h | Move cursor left |
j | Move cursor down |
k | Move cursor up |
l | Move cursor right |
b | Traverse text content backward, cursor on first character of each word |
e | Traverse text content forward, cursor on last character of each word |
w | Traverse text content one word at a time |
/ | Search forward |
? | Search backward |
n | Next keyword occurrence |
N | Previous keyword occurrence |
[Spacebar] | Begin selection |
[Enter] | Copy selection |
ESC | Clear selection |
Ctrl+b ] | Paste selection |
Ctrl+b :show-buffer | Display buffer_0 contents |
Ctrl+b :capture-pane | Copy whole visible contents of the pane to a buffer |
Ctrl+b :list-buffers | Show all buffers |
Ctrl+b :choose-buffer | Show all buffers and paste selected |
Ctrl+b :save-buffer buf.txt | Save buffer contents to buf.txt |
Ctrl+b :delete-buffer -b 1 | Delete 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.
Command | Description |
---|---|
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 | Replace trigger key combination Ctrl+b with Ctrl+a |
Making Tmux Copy Mode to default to vi keys
Command | Description |
---|---|
setw -g mode-keys vi | Use vi keys in the buffer |
Customization
The following commands are for customizing the status bar at the bottom of a Tmux window:
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.