tmux helps you keep your programs alive even after disconnecting from the server, and works as follows. In this example we will be using tmux on the syvert0 server.
|Create a new window
|Switch to the next window
|Switch to the previous window
|Switch directly to window number 0 to 9
|Switch back to the last (most recently shown) window
| Detach from tmux session
Puts tmux in the background
| (Control+b, comma)
Rename the current window
| Ctrl+b, PageUp
|Switch to scroll-back mode. Exit by pressing Escape.
| Forcibly destroy the current window.
Use only if the window doesn't respond. It's better to close the window by running the
exit shell command or pressing
|Tmux usually "swallows" the Ctrl+b keypress. To send an Ctrl+b keypress to the program running inside tmux, press Ctrl+b twice.
Start a new tmux session
After logging in on the server, run
NOTE: Tmux must be run on the server. If you by mistake start tmux on your local computer instead of on the server, and then proceed to log in to the server inside your local tmux session, your computations will not be protected by tmux and may be interrupted in case of network problems.
The green status bar at the bottom of the window indicates that tmux is running:
Any computation you start from inside tmux will keep running even if you get disconnected.
Reconnect to a tmux session
The next time you connect to the server, you can reconnect to your tmux session by running
The green status bar at the bottom will re-appear.
tmux attach outputs
you don't have an existing tmux session (the server may have rebooted, or you didn't use tmux the last time you connected),
and you can start a new tmux session by running
How to manage several tmux sessions
It is possible to have several tmux sessions running simultaneously.
tmux ls will show a list of your currently running tmux sessions,
To choose which one
tmux attach should reconnect to,
tmux attach -t SESSION (in this example, 0 or 1).
-t flag, tmux will reconnect to the most recently used session.
But don't do this. A better solution is to start a single tmux session, and open several command line shells inside the one tmux session. See next section.
How to run several programs in one tmux session
You can run several programs in one tmux session by opening several tmux windows inside your existing tmux session. Each tmux window runs its own shell and has its command prompt, just like a new Terminal window would.
To open a new tmux window, press Ctrl+b, c (mnemonic: "c" for "create). The green status bar at the bottom now shows that your session has two tmux windows:
- Session (orange arrow): The tmux session number/name is shown inside the square brackets.
- Window list (blue arrow): The tmux windows appear here, and are numbered from 0 and up.
- Status information (yellow arrow): The hostname of the server is shown along with the current date and time.
To navigate between the different windows, use Ctrl+b, n to move to the next window, Ctrl+b, p to move to the previous, or Ctrl+b, N (where N is a digit) to jump directly to window number N.
To close a window, log out from the terminal by typing
exit or pressing
Ctrl+d while the shell prompt is displayed.
For other navigation options, see the cheat sheet at the top of this page.
Symbol explanation: In the above example, both windows (0 and 1) are named bash. Behind the window name, some symbols are shown:
|Denotes the current window.
|Marks the last window (previously selected).
|A bell has occurred in the window. Some programs ring the bell when errors occur.