tmux lets you run, switch between, and monitor several terminal tasks inside a single window by splitting it into panes and organizing them into tabs called windows. You start tmux, launch your programs, then use keyboard shortcuts to jump between them without losing state, even if you disconnect. This article explains how tmux structures that workspace and how to make it work for you.
What tmux Actually Is
tmux is a terminal multiplexer: a program that runs inside your terminal and creates a persistent session that holds multiple virtual terminals. Each virtual terminal runs its own shell or command, and tmux keeps them all alive in the background. If you close the terminal window or lose your SSH connection, the session keeps running; when you reconnect, you attach back to the exact same screen. This is the core feature that makes tmux valuable for anyone who works with multiple tasks at once.
How tmux Organizes Work: Sessions, Windows, Panes
tmux uses a three-level hierarchy to organize tasks. Understanding these three levels is the key to using it effectively.
- Sessions – A session is a complete workspace. You can have several sessions, each with its own name, and switch between them. Sessions are useful for separating projects or contexts (e.g., one for coding, one for server logs).
- Windows – Within a session, you can create multiple windows, like tabs in a browser. Each window shows a full-screen terminal. Windows are handy for grouping related tasks (e.g., one window for the editor, one for the test runner).
- Panes – A window can be split into panes, which are rectangular regions that each contain a separate terminal. Panes let you see multiple tasks at once without switching tabs. You can split horizontally or vertically and resize panes freely.
This hierarchy means you can have a session for a project, windows for different stages, and panes for simultaneous commands – all within one terminal window.
Getting Started: Your First tmux Session
To start using tmux, you typically install it with your package manager (e.g., apt install tmux on Debian/Ubuntu, brew install tmux on macOS, or pacman -S tmux on Arch). Then, in your terminal, type:
tmux new -s work
This creates a new session named “work� and attaches to it. You’ll see a green status bar at the bottom showing the session name, window list, and time. Now you can start using tmux’s shortcuts. The default prefix key is Ctrl-b – you press that first, then the command key.
Here are the essential commands:
Ctrl-b c– create a new windowCtrl-b p/Ctrl-b n– switch to previous/next windowCtrl-b %– split the current pane vertically (left/right)Ctrl-b "– split the current pane horizontally (top/bottom)Ctrl-b arrow– move between panesCtrl-b d– detach from the session (it keeps running)Ctrl-b ?– show all key bindings
After detaching, you can reattach with tmux attach -t work. That’s the whole cycle: create, organize, detach, reattach.
Practical Example: A Development Workspace
Imagine you’re writing a web app. You want to edit code, run a dev server, and check logs – all without switching windows. Here’s a typical workflow:
- Start a new session:
tmux new -s dev - In the first pane, open your editor (e.g., vim or nano).
- Split vertically with
Ctrl-b %. In the new pane, runnpm startto start the server. - Split the right pane horizontally with
Ctrl-b ". In that pane, runtail -f log.txtto watch logs. - Now you see all three at once. Use
Ctrl-b oto cycle through panes, orCtrl-b arrowto jump directly. - When you’re done, detach with
Ctrl-b d. The server keeps running. Later, reattach withtmux attach -t devand pick up exactly where you left off.
This pattern works for any multi-process workflow: compiling while editing, running tests while watching output, or monitoring system logs while issuing commands.
Choosing Between Panes and Windows
The main decision is when to use panes versus windows. Panes are best when you need to see multiple outputs simultaneously – for example, watching a build while editing the source. Windows are better when tasks are independent and you don’t need to see them at once, because each window gives you full screen space and reduces clutter.
A common rule of thumb: if you need to glance at a task frequently, make it a pane; if you only check occasionally, put it in a separate window. You can also convert a pane into a window with Ctrl-b ! (break pane) or move a window into a pane with Ctrl-b . (move window).
Common Problems and How to Fix Them
New users often hit a few stumbling blocks:
- Forgot the prefix – If you press
Ctrl-band nothing happens, you might be in a different terminal that intercepts it, or you’re not in a tmux session. Check the status bar. - Accidentally closed a pane – If you type
exitin a pane, it closes. If that was the last pane, the window closes, and if the last window, the session ends. To avoid losing work, useCtrl-b dto detach instead of exiting. - Can’t scroll – By default, tmux doesn’t let you scroll with the mouse wheel. Enter copy mode with
Ctrl-b [and use arrow keys or PageUp/PageDown to scroll. Pressqto exit. - Mouse doesn’t work – Enable mouse support in your config file with
set -g mouse on. Then you can click panes and scroll normally. - Lost session after reboot – tmux sessions don’t survive a system reboot. For that, you need tmux-resurrect or a similar plugin, but that’s beyond basic usage.
Alternatives and When to Use Them
tmux is not the only terminal multiplexer. GNU Screen is older and simpler, with similar features but fewer options. Some terminal emulators (like iTerm2 on macOS or Konsole on Linux) have built-in split panes and tabs, but they don’t persist sessions after the terminal closes. If you only need splits within a single terminal window and don’t care about persistence, those built-ins are simpler. However, if you work over SSH or want sessions that survive disconnects, tmux (or Screen) is the standard choice.
Customizing tmux to Fit Your Workflow
tmux is highly configurable through a ~/.tmux.conf file. Common customizations include changing the prefix key (e.g., Ctrl-a), enabling the mouse, and setting a larger history limit. For example:
set -g prefix C-a
set -g mouse on
set -g history-limit 10000
After editing, reload with tmux source-file ~/.tmux.conf. You can also create custom key bindings to automate repetitive tasks, like a single key that splits a pane and runs a specific command. But start with the defaults – they’re well chosen.
Frequently Asked Questions
How do I exit tmux without killing my session?
Press Ctrl-b then d to detach. Your session and all its processes keep running in the background. You can reattach later with tmux attach.
Can I use tmux with SSH to keep my work alive?
Yes, that’s a common use case. Start a tmux session on the remote server, run your tasks, and detach. When you disconnect and reconnect, your session is still there. This is especially useful for long-running processes like downloads or builds.
How do I resize a pane?
Press Ctrl-b then hold Ctrl and press the arrow keys to resize the current pane. Alternatively, use Ctrl-b : to enter command mode and type resize-pane -R 10 to resize right by 10 cells.
What’s the difference between tmux and screen?
tmux is newer, more actively maintained, and has a more modern configuration system. Screen is older and simpler. Both provide sessions, windows, and splits. tmux has better scripting support and a cleaner status bar. For most new users, tmux is recommended.
Why does my terminal show weird characters when I use tmux?
This usually happens when your terminal’s color scheme or character encoding doesn’t match tmux’s defaults. Try setting set -g default-terminal "screen-256color" in your config, or ensure your terminal uses UTF-8 encoding.
Can I share a tmux session with another user?
Yes, you can set the socket path and permissions, but it requires careful configuration. A simpler approach is to use tmux new -s shared and then have the other user attach to the same socket with tmux attach -t shared if they have permission. For secure sharing, consider using a tool like tmate, which is built on tmux.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.
More cards in this drawer
- Screen Fatigue: Why Bad Screens Hurt & Good Ones Help84
- Pivot Tables to Groupby: Does Analysis Auto-Update?10 rows
- Sennheiser Momentum 4 Launch in India: Status & Details416.50 ₹/h
- Ryobi 18V vs 40V Yard Tools: Which to Choose
- Knockout Penguin Skins? Real Facts
- VS Code Settings: Coding Less of a Chore?5.00 min/km