tmux Quickstart
Last Update:
Word Count:
Read Time:
Page View: loading...
Getting Started with [tmux] for a Powerful Terminal
tmux is a terminal multiplexer, a powerful tool that transforms your terminal into a persistent, multi-window workspace. It’s an essential utility for anyone working on remote servers or managing multiple tasks in the command line. Think of it as adding tabs and session-saving capabilities to your terminal.
Installing [tmux]
Getting tmux is straightforward on most systems.
- On macOS (with Homebrew):
1
brew install tmux - On Debian / Ubuntu:
1
2sudo apt update
sudo apt install tmux - On CentOS / RHEL / Fedora:
1
sudo dnf install tmux
Managing Sessions and Windows
tmux commands are triggered by a prefix key, which is Ctrl + b by default. To send a command, you press the prefix, release it, and then press the command key.
Creating and Managing Sessions
A session is a collection of windows that can be detached and re-attached later.
- Start a new named session:
1
tmux new -s my_project Detach from the current session:
This leaves the session running in the background.
PressCtrl + b, thend.List all running sessions:
1
tmux lsRe-attach to a session:
1
tmux attach -t my_project
Managing Windows (like browser tabs)
Within a session, you can have multiple windows for different tasks.
Create a new window:
PressCtrl + b, thenc.Switch between windows:
Ctrl + b, thenn(next window)Ctrl + b, thenp(previous window)Ctrl + b, then0(switch to window 0)
Rename the current window:
PressCtrl + b, then,(comma).Close the current window:
PressCtrl + b, then&.
Browsing Command History and Buffer
Sometimes, the output of a command is too long to fit on one screen. tmux has a special “copy mode” that lets you scroll up and view your history.
Enter Copy Mode (Scroll Mode):
PressCtrl + b, then[(left square bracket).Navigate the buffer:
Once in copy mode, you can use your arrow keys (Up,Down,Left,Right) or Vim-style keys (kfor up,jfor down) to scroll freely through the entire command output history of that pane.Exit Copy Mode:
Pressqto return to the normal command prompt.
Managing [tmux] from the Outside
You don’t have to be inside a tmux session to manage it. You can use command-line flags to get information or to stop sessions and windows.
List all sessions and their windows (detailed view):
Thelscommand is your primary tool for this.1
tmux lsDelete a specific session from outside:
If you want to completely shut down a session and all the processes within it, usekill-session.1
tmux kill-session -t my_projectReplace
my_projectwith the name or ID of the session you want to delete.Delete a specific window from outside:
This is less common, but you can target a specific window to close it. You need to specify the target using the format[session_name]:[window_index].1
tmux kill-window -t my_project:1this command will kill window 1 in the ‘my_project’ session
[tmux] Structure Relationship
To help you visualize how everything fits together, here is a simple diagram. The tmux server runs in the background. It can manage multiple sessions. Each session acts as a workspace containing one or more windows (like tabs). Finally, each window can be split into one or more panes.
1 | |
Key [tmux] Features Explained
What makes tmux so indispensable?
Session Persistence: This is the killer feature. When you detach or your SSH connection drops, the
tmuxserver keeps your session and all its running processes alive in the background. You can reconnect later and find everything exactly as you left it.Environment Variable Isolation: When you
exportan environment variable in onetmuxpane or window, it is not automatically available in other existing or new windows/panes. Each new window starts with a clean environment, preventing variables from one task from accidentally affecting another. This ensures a predictable and isolated workspace for each command.Backgrounding: The ability to detach (
Ctrl + b,d) and leave tasks running is crucial for long-running processes like code compilation, data processing, or server maintenance. You can start a job, detach, close your local terminal, and re-attach hours later from a different machine to check the progress.Panes and Layouts: Beyond windows, you can split a single window into multiple panes (horizontal:
Ctrl + b,"; vertical:Ctrl + b,%) to view logs, edit code, and run commands all at once.