50+ tmux cheat sheet and shortcut commands

50+ tmux cheat sheet and shortcut commands

In this tutorial, we'll explore tmux, covering essential commands, session management, window and pane operations, and customization techniques to enhance your command-line efficiency.

tmux is a terminal multiplexer, an essential tool for command-line users, especially developers, system administrators, and power users. It allows for multiple terminal sessions to be created, accessed, and controlled from a single screen. tmux sessions are persistent, meaning they continue to run even when not actively connected, which is particularly useful for remote work. Inside tmux, users can split the view horizontally or vertically, creating multiple panes within a single window. This feature facilitates multitasking and enhances productivity by enabling users to monitor and manage several tasks simultaneously. With customization options, users can tailor tmux to fit their workflow, making it a versatile tool for a wide range of command-line activities.


1. Installing tmux

Below are the commands for installing tmux on various Linux distributions, as well as for Mac and BSD systems:

text
# Debian/Ubuntu
sudo apt-get install tmux

# Fedora
sudo dnf install tmux

# CentOS/RHEL
sudo yum install tmux

# Arch Linux
sudo pacman -S tmux

# openSUSE
sudo zypper install tmux

# Gentoo
sudo emerge tmux

# Slackware
sudo slackpkg install tmux

# FreeBSD
sudo pkg install tmux

# OpenBSD
sudo pkg_add tmux

# Mac (using Homebrew)
brew install tmux

2. Starting and Managing Sessions

Here's a table summarizing key commands for starting and managing sessions in tmux:

ActionCommand
Start a new sessiontmux or tmux new
Start a new named sessiontmux new -s [session-name]
List all sessionstmux ls or tmux list-sessions
Attach to the last sessiontmux attach or tmux a
Attach to a specific sessiontmux attach -t [session-name]
Detach from the current sessionCtrl+b d
Rename the current sessionCtrl+b $
Switch to the next sessionCtrl+b )
Switch to the previous sessionCtrl+b (
Kill the current sessionCtrl+b &
Kill a specific sessiontmux kill-session -t [session-name]

This table covers the basic operations for handling tmux sessions, including creating, listing, attaching to, detaching from, and killing sessions. Remember, Ctrl+b is the default prefix key in tmux, which you press before entering any command keybindings.


3. Working with Windows

Here's a table with commands for managing windows in tmux:

ActionCommand
Create a new windowCtrl+b c
List all windowsCtrl+b w
Rename the current windowCtrl+b ,
Close the current windowCtrl+b &
Move to the next windowCtrl+b n
Move to the previous windowCtrl+b p
Move to a specific window by numberCtrl+b [0-9]
Swap current window with anotherCtrl+b :swap-window -t [index]

4. Managing Panes

Here's a table for pane management commands in tmux:

ActionCommand
Split the pane horizontallyCtrl+b "
Split the pane verticallyCtrl+b %
Switch to the next paneCtrl+b o
Rotate panesCtrl+b Ctrl+o
Close the current paneCtrl+b x
Toggle between panesCtrl+b ;
Resize pane (Up, Down, Left, Right)Ctrl+b [arrow key]
Convert pane into a new windowCtrl+b !
Toggle pane layoutsCtrl+b Spacebar
Synchronize panesCtrl+b :setw synchronize-panes

5. Advanced Features

Here's a table with advanced tmux commands for more sophisticated operations:

FeatureCommand
Enter copy modeCtrl+b [
Paste from bufferCtrl+b ]
Save buffer content to a fileCtrl+b :save-buffer [file-name]
Load buffer content from a fileCtrl+b :load-buffer [file-name]
Search in copy mode/[search-text] in copy mode
Navigate between panes in copy modeCtrl+b [arrow keys] in copy mode
Capture pane contentCtrl+b :capture-pane
Send keys to all panesCtrl+b :setw synchronize-panes on
Toggle mouse supportCtrl+b :set-option -g mouse on
Resize pane in larger steps`Ctrl+b :resize-pane -[L

6. Customizing tmux configuration

Below is a table outlining commands for customizing tmux to tailor it to your preferences:

CustomizationCommand
Edit tmux configuration filevim ~/.tmux.conf
Reload tmux configurationCtrl+b :source-file ~/.tmux.conf
Change prefix keyset -g prefix [key] in .tmux.conf
Change status bar colorset -g status-bg [color] in .tmux.conf
Set default terminal window sizeset -g window-size [width]x[height] in .tmux.conf
Customize pane border colorset -g pane-border-style fg=[color] in .tmux.conf
Bind new key for a commandbind-key [key] [command] in .tmux.conf
Change default pane layoutsetw -g main-pane-height [size] in .tmux.conf

7. Keybindings Cheat Sheet

Here's a tmux keybindings cheat sheet that provides quick references for commonly used shortcuts:

ActionKeybinding
Start new sessionCtrl+b c
List sessionsCtrl+b s
Detach from current sessionCtrl+b d
Switch to next sessionCtrl+b )
Switch to previous sessionCtrl+b (
Rename current sessionCtrl+b $
Split pane horizontallyCtrl+b "
Split pane verticallyCtrl+b %
Switch to next paneCtrl+b o
Toggle last active paneCtrl+b ;
Resize pane up/down/left/rightCtrl+b [arrow key]
Convert pane into a windowCtrl+b !
Close current paneCtrl+b x
Enter copy modeCtrl+b [
Paste from bufferCtrl+b ]
Search in copy mode (backward/forward)Ctrl+b ? / /
Reload tmux configurationCtrl+b :source-file ~/.tmux.conf

These keybindings are the default settings in tmux and can be customized in the tmux configuration file. For more detailed information and additional keybindings, the tmux manual page (man page for tmux) is a comprehensive resource.

Deepak Prasad

Deepak Prasad

R&D Engineer

Founder of GoLinuxCloud with over a decade of expertise in Linux, Python, Go, Laravel, DevOps, Kubernetes, Git, Shell scripting, OpenShift, AWS, Networking, and Security. With extensive experience, he excels across development, DevOps, networking, and security, delivering robust and efficient solutions for diverse projects.