What Is tmux Actually Used For?
Most introductions to tmux begin with commands and keybindings:
- create a session;
- detach from it;
- create another window;
- split the screen into panes;
- switch among them.
That explains how to operate tmux, but it does not explain why the tool exists.
At its core, tmux solves two major problems:
- You want to leave an interactive terminal and return to it later.
- You want to see one terminal context while acting in another.
Sessions, windows, and panes are the mechanisms tmux provides for solving and organizing those problems.
The ordinary terminal limitation
Suppose you start a program you are developing:
./my-program
The program writes diagnostic information directly to standard output and standard error:
Starting server on port 8080
Connected to database
Received request: GET /users
Assume this is ordinary console output from printf, Console.WriteLine, fmt.Println, console.log, or an equivalent function.
The program is not writing to a log file. No logging system has been configured. Its output is appearing directly in the terminal.
The terminal is now occupied by the running program.
But while debugging it, you may also need to run commands such as:
ps aux
ss -lntp
curl localhost:8080/users
docker ps
nano config.json
You want the program to keep running, but you also want a usable shell.
Without tmux, how would you solve that?
Backgrounding gives you the prompt back
One option is to run the program in the background:
./my-program &
This returns the shell prompt, but the program is still connected to the same terminal. Its output can appear between your prompt and the commands you type:
$ curl localhost:8080/users
Received request: GET /users
[{"id":1,"name":"Alice"}]
$
Database connection refreshed
That may be acceptable for a simple process, but it becomes awkward quickly.
The shell and the program are sharing the same visible terminal. If the program expects interactive input, foreground and background job control introduce additional complications.
Backgrounding gives you the prompt back. It does not give the program its own terminal context.
Redirection preserves the output somewhere else
You could redirect the program’s output to a file:
./my-program >program.log 2>&1 &
Now the program continues running without filling your terminal. You can inspect its output separately:
tail -f program.log
This is often a perfectly good solution.
But it changes the workflow.
You are no longer returning to the program’s original console. You have arranged for its output to be written somewhere else, and you are reading that destination independently.
That distinction matters when the program is interactive, when the terminal state itself is useful, or when you simply want to return to exactly what was on the screen.
Keeping a process alive is not the same as preserving its console
Shell features and tools such as nohup, disown, and setsid can help a process continue independently of the shell that launched it.
For example:
nohup ./my-program >program.log 2>&1 &
The process may continue running after the original shell exits.
You can later find it:
ps aux | grep my-program
But finding the process by PID does not give you its terminal back.
A process’s standard output is represented by an already-open file descriptor inside that process. A new shell cannot normally decide that the process’s existing file descriptor 1 should now point to the new shell’s terminal.
If the output was redirected to a file, you can read the file.
If it was redirected to /dev/null, the output was discarded.
If it remained associated with an old terminal device, that still does not provide a normal way to attach a new terminal and recover the original interactive screen.
There are specialized recovery tools that can sometimes move a process to another terminal, but those are recovery techniques rather than the normal workflow.
The important distinction is:
Process detachment preserves execution.
tmuxpreserves the terminal context around that execution.
tmux preserves the terminal itself
When a program runs inside tmux, the program is attached to a pseudo-terminal managed by the tmux server.
You can detach from the tmux client:
Ctrl-b d
The program continues writing to the same pseudo-terminal. The shell remains there. The screen remains there. The program can remain interactive.
Later, you can reattach:
tmux attach
You return to the terminal context you left.
This is more than keeping a PID alive. It preserves the relationship among:
- the shell;
- the running program;
- standard input;
- standard output;
- standard error;
- the pseudo-terminal;
- the visible terminal state.
This is the first major use case for tmux:
Keep an interactive terminal running, leave it, and return to it later.
Why this becomes especially noticeable over SSH
Locally, the simplest solution to an occupied terminal is often:
Open another terminal window.
That is nearly effortless. Press a keyboard shortcut and another shell appears.
When working on a remote machine, the equivalent is often to open another local terminal and establish another SSH connection:
ssh server.example.com
There is nothing technically wrong with doing that. Multiple SSH connections are normal.
But it can feel strange to create another network connection merely because one remote shell is occupied by a running process.
If you need several contexts, you may end up with several local terminal windows, each containing a separate SSH connection to the same machine.
tmux moves that organization to the remote side. One SSH connection can contain multiple remote shells, windows, and panes. If the network connection disappears, the remote terminal contexts remain inside tmux.
SSH does not create the underlying problem. It merely makes the problem more noticeable.
Locally, opening another terminal hides the limitation because doing so is almost frictionless. Remotely, the same workaround feels more explicit.
The second problem: seeing and acting at the same time
The second major use case is different.
Sometimes you do not merely need another shell. You need to keep one piece of information visible while working with another.
For example, you may want to:
- run a server in one pane and send requests from another;
- tail logs while reproducing a bug;
- watch
docker psoutput while entering a container; - keep a configuration file visible while typing a command derived from it;
- watch process or network activity while changing the system;
- keep a long identifier, path, or command visible rather than memorizing it;
- compare two files or command outputs.
You can often solve these problems without panes.
You can run a command, inspect its output, and then type the next command a few lines below it. You can use grep, sed, awk, pipes, command substitution, temporary files, or shell variables. You can switch between terminal windows.
But sometimes the simplest solution is simply to see two things at once.
A pane allows one terminal context to remain visible while you operate in another.
See in one pane; act in another.
Panes as external working memory
Consider a long Docker container ID:
f31b8fc2d387fb263ad97641d645f2d29422a584cc97074c893f2fb361f87d6b
Usually, you do not need the entire value. You may use the short ID, copy it, filter the output, or use command substitution.
But the larger pattern appears everywhere:
- a complicated path inside a configuration file;
- a long command you want to reproduce with one modification;
- several values that must be entered elsewhere;
- output that changes while you perform an action;
- logs that must remain visible while you trigger a request.
Human working memory is limited. There is little value in memorizing information that the computer can simply leave visible.
Panes externalize that memory. Instead of switching away from a reference and attempting to retain it mentally, you keep the reference on the screen.
This makes panes more than a cosmetic feature. They are a way of coordinating related terminal activities.
Observing one thing while changing another
Panes are especially useful when observation and action happen together.
In one pane:
tail -f application.log
In another:
curl -X POST localhost:8080/rebuild-index
You can immediately see how the application responds.
Or in one pane:
watch -n 1 'ps -o pid,%cpu,%mem,cmd -C my-program'
In another:
./load-test
One pane shows the system state. The other changes it.
This is not merely having two terminals. The value comes from their simultaneous visibility.
Sessions, windows, and panes preserve different kinds of context
The tmux hierarchy can initially feel arbitrary. It becomes easier to understand when each level is treated as preserving a different kind of context.
Sessions preserve a broader workspace
A session contains the complete collection of windows and panes associated with some broader activity.
You might have one session for a project, another for administering a server, and another for an unrelated investigation.
For example:
tmux new -s my-project
You can detach from the session:
Ctrl-b d
Then return later:
tmux attach -t my-project
Everything inside the session remains intact.
A session answers:
Which broader workspace do I want to enter?
Windows preserve switchable terminal environments
A window contains one or more panes arranged for a particular kind of activity.
For example, one window might contain an editor, an application server, and a test watcher:
Window 1: Development
+----------------------+----------------------+
| editor | application server |
+----------------------+----------------------+
| test watcher |
+---------------------------------------------+
Another window might contain logs, a database client, and a system monitor:
Window 2: Investigation
+----------------------+----------------------+
| tail -f logs | shell |
+----------------------+----------------------+
| database client | system monitor |
+----------------------+----------------------+
Switching windows changes the complete visible arrangement without destroying the arrangement you were previously using.
Without windows, you would have to close, resize, or repurpose the panes whenever your task changed. A window lets the entire pane layout remain intact while you move to another one.
Windows therefore feel like preconfigured environments. They do not have to be declared or automated in advance, but once you have arranged them, tmux preserves them as switchable terminal layouts.
A window answers:
Which terminal environment do I need right now?
Panes expose related contexts simultaneously
Panes are the individual terminals visible inside a window.
They are useful when the relationship among several contexts is immediate enough that you want to see them together.
For example:
+-----------------------------------+
| application server |
| |
| |
+------------------+----------------+
| tail -f logs | curl / inspect |
| | |
+------------------+----------------+
A pane answers:
Which related contexts need to be visible together?
The distinction can be summarized as:
Sessions preserve broader workspaces. Windows preserve switchable terminal environments. Panes expose related terminal contexts simultaneously.
tmux is not only for remote servers
Because tmux is frequently discussed alongside SSH, it can appear to be primarily a remote-administration tool.
It is not.
The same two underlying problems exist locally:
- preserving an interactive terminal context;
- seeing one context while acting in another.
Graphical terminal emulators already make the second problem easier by providing tabs, splits, and multiple windows. Service managers, IDEs, and container tools may also reduce the need to leave long-running processes attached to a terminal.
That can make tmux feel less necessary on a local workstation.
But it remains useful when you want:
- the same terminal workflow locally and remotely;
- a workspace controlled entirely from the keyboard;
- named and persistent project sessions;
- terminal organization independent of a particular graphical terminal emulator;
- the ability to detach from an entire workspace and restore it later.
When tmux is unnecessary
Not every long-running process belongs in tmux.
A real service should usually be managed as a service.
Depending on the environment, that may mean:
systemd;- Docker;
- Kubernetes;
- a process supervisor;
- a scheduled job;
- a cloud service manager.
Those systems provide lifecycle management, restart policies, structured logging, health checks, and other operational behavior that tmux does not attempt to provide.
Similarly, if a program already writes useful logs to a file or centralized logging system, you may not need to preserve its console output.
tmux is most valuable for interactive work:
- development;
- debugging;
- investigation;
- manual administration;
- temporary long-running commands;
- exploratory workflows;
- processes you expect to return to directly.
It preserves a terminal workspace. It is not a replacement for process supervision or service management.
The two major use cases
Most everyday uses of tmux reduce to two ideas.
1. Leave and return
You want to start or enter an interactive terminal context, leave it without destroying it, and return later.
This is what sessions primarily make possible.
2. See and act
You want to keep one context visible while inspecting, modifying, or triggering something in another context.
This is what panes primarily make possible.
Windows sit between those two ideas. They preserve complete arrangements of panes so that you can switch among different terminal environments without destroying and rebuilding each layout.
Once these problems are understood, the tmux feature set becomes much less arbitrary.
tmux is not fundamentally a collection of terminal shortcuts.
It is a way to make terminal contexts persistent, organized, switchable, and simultaneously observable.
Comments
No comments yet. Be the first!