The Tao of tmux¶
tmux is geared for developers and admins who interact regularly with CLI (text-only interfaces)
In the world of computers, there are 2 realms:
The text realm
The graphical realm
tmux resides in the text realm. This is about fixed-width fonts and that old fashioned black terminal.
tmux is to the console what a desktop is to gui apps. It’s a world inside the text dimension. Inside tmux you can:
multitask inside the terminal, run multiple applications.
have multiple command lines (pane) in the same window
have multiple windows (window) in the workspace (session)
switch between multiple workspaces, like virtual desktops
Thinking tmux¶
Text-based window manager¶
tmux |
“Desktop”-Speak |
Plain English |
---|---|---|
Multiplexer |
Multi-tasking |
Multiple applications simultaneously. |
Session |
Desktop |
Applications are visible here |
Window |
Virtual Desktop or applications |
A desktop that stores it own screen |
Pane |
Application |
Performs operations |
See also
Glossary has a dictionary of tmux words.
CLI Power Tool¶
Multiple applications or terminals to run on the same screen by splitting up 1 terminal into multiple.
One screen can be used to edit a file, and another may be used to
$ tail -F
a logfile.
tmux supports as manys terminals as you want.
You can switch between the windows you create.
Resume everything later¶
You can leave tmux and all applications running (detach), log out, make a sandwich, and re-(attach), all applications are still running!
Manage workflow¶
System administrators monitor logs and services.
Programmers like to have an editor open with a CLI nearby.
Applications running on a remote server can be launched inside of a tmux session, detached, and reattached next timeyour “train of thought” and work.
Multitasking. Preserving the thinking you have.
Installing tmux¶
tmux is packaged on most Linux and BSD systems.
For the freshest results on how to get tmux installed on your system, “How to install tmux on <my distro>” will do, as directions change and are slightly different between distributions.
This documentation is written for version 1.8. It’s important that you have the latest stable release of tmux. The latest stable version is viewable on the tmux homepage.
Mac OS X users may install that latest stable version of tmux through MacPorts, fink or Homebrew (aka brew).
If compiling from source, the dependencies are libevent and ncurses.
Using tmux¶
Start a new session¶
$ tmux
That’s all it takes to launch yourself into a tmux session.
Common pitfall
Running $ tmux list-sessions
or any other command for listing tmux
entities (such as $ tmux list-windows
or $ tmux list-panes
).
This can generate the error “failed to connect to server”.
This could be because:
tmux server has killed its’ last session, killing the server.
tmux server has encountered a crash. (tmux is highly stable, this will rarely happen)
tmux has not be launched yet at all.
The prefix key¶
Tmux hot keys have to be pressed in a special way. Read this carefully, then try it yourself.
First, you press the prefix key. This is C-b
by default.
Release. Then pause. For less than second. Then type what’s next.
C-b o
means: Press Ctrl
and b
at the same time. Release, Then
press o
.
Remember, prefix + short cut! C
is Ctrl
key.
Session Name¶
Sessions can be named upon creation.
$ tmux new-session [-s session-name]
Sessions can be renamed after creation.
Command |
$ tmux rename-session <session-name>
|
Short cut |
|
Window Name¶
Windows can be named upon creation.
$ tmux new-window [-n window-name]
Windows can be renamed after creation.
Command |
$ tmux rename-window <new-name>
|
Short cut |
|
Creating new windows¶
Command |
$ tmux new-window [-n window-name]
|
Short cut |
You may then rename window. |
Traverse windows¶
By number
$ tmux select-window
Next
$ tmux next-window
Previous
$ tmux previous-window
Last-window
$ tmux last-window
Short cut |
Action |
---|---|
|
Change to the next window. |
|
Change to the previous window. |
|
Choose the current window interactively. |
|
Select windows 0 to 9. |
|
Move to the next window with a bell or activity marker. |
|
Move to the previous window with a bell or activity marker. |
Move windows¶
Move window
$ tmux move-window [-t dst-window]
Swap the window
$ tmux swap-window [-t dst-window]
Short cut |
Action |
---|---|
|
Prompt for an index to move the current window. |
Move panes¶
$ tmux move-pane [-t dst-pane]
Short cut |
Action |
---|---|
|
Rotate the panes in the current window forwards. |
|
Swap the current pane with the previous pane. |
|
Swap the current pane with the next pane. |
Traverse panes¶
Shortcut to move between panes.
$ tmux last-window
$ tmux next-window
Short cut |
Action |
---|---|
|
Change to the pane above, below, to the left, or to |
|
the right of the current pane. |
Recipe: tmux conf to hjkl
commands, add this to your ~/.tmux.conf
:
# hjkl pane traversal
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R
Kill window¶
$ tmux kill-window [-t target-window]
Short cut |
Action |
---|---|
|
Kill the current window. |
Kill pane¶
$ tmux kill-pane [-t target-pane]
Short cut |
Action |
---|---|
|
Kill the current pane. |
Splitting windows into panes¶
$ tmux split-window [-c start-directory] <shell-command>
Tmux windows can be split into multiple panes.
Short cut |
Action |
---|---|
|
Split the current pane into two, left and right. |
|
Split the current pane into two, top and bottom. |
Configuring tmux¶
Tmux can be configured via a tmux(1)
configuration at ~/.tmux.conf
.
Depending on your tmux version, there is different options available.
Vi-style copy and paste¶
# Vi copypaste mode
set-window-option -g mode-keys vi
bind-key -t vi-copy 'v' begin-selection
bind-key -t vi-copy 'y' copy-selection
Aggressive resizing for clients¶
setw -g aggressive-resize on
Reload config¶
<Prefix>
+ r
.
bind r source-file ~/.tmux.conf \; display-message "Config reloaded."
Status lines¶
Tmux allows configuring a status line that displays system information,
window list, and even pipe in the stdout
of an application.
You can use tmux-mem-cpu-load to get stats (requires compilation) and basic-cpu-and-memory.tmux. You can pipe in a bash command to a tmux status line like:
$(shell-command)
So if /usr/local/bin/tmux-mem-cpu-load
outputs stats to stdout
, then
$(tmux-mem-cpu-load)
is going to output the first line to the status
line. The interval is determined by the status-interval
:
set -g status-interval 1
Examples¶
https://github.com/tony/tmux-config - works with tmux 1.5+. Supports screen’s
ctrl-a
Prefix key
. Support for system cpu, memory, uptime stats.Add yours, edit this page on github.
Reference¶
Short cuts¶
Tip
The prefix key is pressed before a short cut!
Short cut |
Action |
---|---|
|
Send the prefix key (C-b) through to the application. |
|
Rotate the panes in the current window forwards. |
|
Suspend the tmux client. |
|
Break the current pane out of the window. |
|
Split the current pane into two, top and bottom. |
|
List all paste buffers. |
|
Rename the current session. |
|
Split the current pane into two, left and right. |
|
Kill the current window. |
|
Prompt for a window index to select. |
|
Rename the current window. |
|
Delete the most recently copied buffer of text. |
|
Prompt for an index to move the current window. |
|
Select windows 0 to 9. |
|
Enter the tmux command prompt. |
|
Move to the previously active pane. |
|
Choose which buffer to paste interactively from a list. |
|
List all key bindings. |
|
Choose a client to detach. |
|
Enter copy mode to copy text or view the history. |
|
Paste the most recently copied buffer of text. |
|
Create a new window. |
|
Detach the current client. |
|
Prompt to search for text in open windows. |
|
Display some information about the current window. |
|
Move to the previously selected window. |
|
Change to the next window. |
|
Select the next pane in the current window. |
|
Change to the previous window. |
|
Briefly display pane indexes. |
|
Force redraw of the attached client. |
|
Select a new session for the attached client interactively. |
|
Switch the attached client back to the last session. |
|
Show the time. |
|
Choose the current window interactively. |
|
Kill the current pane. |
|
Swap the current pane with the previous pane. |
|
Swap the current pane with the next pane. |
|
Show previous messages from tmux, if any. |
|
Enter copy mode and scroll one page up. |
|
Change to the pane above, below, to the left, or to |
|
the right of the current pane. |
|
Arrange panes in one of the five preset layouts: even-horizontal, even-vertical, main-horizontal, main-vertical, or tiled. |
|
Move to the next window with a bell or activity marker. |
|
Rotate the panes in the current window backwards. |
|
Move to the previous window with a bell or activity marker. |
|
Resize the current pane in steps of one cell. |
|
Resize the current pane in steps of five cells. |
Source: tmux manpage[1].
To get the text documentation of a .1
manual file:
$ nroff -mdoc tmux.1|less
For more information on how to export and differentiate tmux between versions, see https://github.com/tmux-python/tmux-manuals.
The Book¶
The Tao of tmux is available on Leanpub and Kindle (Amazon).
Read and browse the book for free on the web.
License¶
This page is licensed Creative Commons BY-NC-ND 3.0 US.