tmux Cheatsheet

A comprehensive quick-reference for the popular terminal multiplexer, tmux, designed to enhance your command-line productivity.

For anyone who spends a significant amount of time in the terminal, managing multiple tasks, sessions, and windows can quickly become a cumbersome process. This is where tmux, a powerful terminal multiplexer, comes into play. It allows you to create and control multiple terminal sessions from a single screen, detach from them while processes continue to run in the background, and reattach later from any terminal. This cheatsheet provides a concise overview of the most essential tmux commands and key bindings to get you up and running.

The Prefix

All tmux commands are initiated with a prefix key, which by default is Ctrl+b. After pressing the prefix, you then press the desired command key.

Session Management

A tmux session is an independent workspace that contains its own set of windows and panes.

Command Description
tmux new or tmux Start a new session.
tmux new -s [session_name] Start a new session with a specific name.
tmux ls List all active tmux sessions.
tmux a or tmux attach Attach to the last used session.
tmux a -t [session_name] Attach to a session with a specific name.
Ctrl+b d Detach from the current session.
Ctrl+b $ Rename the current session.
tmux kill-ses -t [session_name] Kill a specific session.
tmux kill-server Kill the tmux server and all sessions.

Window Management

Within a session, you can create multiple windows, which are akin to tabs in a web browser.

Keystroke Description
Ctrl+b c Create a new window.
Ctrl+b , Rename the current window.
Ctrl+b w List all windows in the current session.
Ctrl+b p Switch to the previous window.
Ctrl+b n Switch to the next window.
Ctrl+b [0-9] Switch to a specific window by its number.
Ctrl+b & Kill the current window.

Pane Management

Panes allow you to split a single window into multiple terminal views, enabling you to see and interact with several shells at once.

Keystroke Description
Ctrl+b % Split the current pane vertically.
Ctrl+b " Split the current pane horizontally.
Ctrl+b [arrow key] Navigate between panes.
Ctrl+b o Cycle through the panes in the current window.
Ctrl+b ; Toggle between the current and the last active pane.
Ctrl+b z Toggle zoom for the current pane.
Ctrl+b x Close the current pane.
Ctrl+b { Swap the current pane with the previous one.
Ctrl+b } Swap the current pane with the next one.

Customization

You can personalize your tmux experience by creating and editing a configuration file located at ~/.tmux.conf. After making changes to this file, you can apply them by either restarting tmux or by sourcing the file with Ctrl+b : followed by source-file ~/.tmux.conf.

Common Customizations:

This cheatsheet covers the fundamental commands to get you started with tmux. With its extensive customization options, tmux can be tailored to fit a wide variety of workflows, making it an indispensable tool for any power user of the command line.