Table of Contents
Tmux
What is tmux?
Tmux is a terminal multiplexer. It allows you to run multiple terminals in a single terminal. In this sense, it is an alternative to screen command.
Tmux runs a background session that you can attach to. It gives you the ability to create multiple windows within a session. Then it also gives you the ability to create multiple panes within a window, and tile them. Each pane contains a terminal. Thus, you can think of tmux as a tiling window manager for the terminal. You don't need a graphical user interface at all. You can run tmux inside any terminal, including over SSH.
Here's what it looks like:
Concepts
Sessions
Sessions are run in the background. You can attach to them from any terminal you like using tmux attach. But first, you have to create at least one session. You create a session by running tmux in the terminal (no arguments). Once you're in a tmux session, you can detach from it by pressing Ctrl + b, d. This means pressing Ctrl + b, releasing both, then pressing d. As mentioned, you can reattach by running tmux attach in any terminal.
Assuming you ran tmux multiple times – meaning you created multiple sessions – you can cycle between sessions with Ctrl + b, ( (previous session) or Ctrl + b, ) (next session). This means pressing Ctrl + b, releasing both, then pressing Shift + 9 or 0, for ( and ) respectively (on English keyboards at least). If you want to kill the session, you press Ctrl + b, : to enter command mode, type in “kill-session”, then hit enter.
Here's a summary of session commands you should know:
tmux- Create a new session (you run this in the terminal)tmux attach- Attach the last session (you run this in the terminal)Ctrl + b, d- Detach the current sessionCtrl + b, (- Switch to previous sessionCtrl + b, )- Switch to next sessionCtrl + b, :tmux kill-session<CR>- Kill the current session
Windows
Windows are part of a session and look somewhat like tabs in a browser. They are listed in the status bar. The one marked with a * is your current window, and the one marked with a - is the one you were previously at.
You create a new window by pressing Ctrl + b, c. This means pressing Ctrl + b, releasing both keys, then pressing c. You'll find that most keybindings are prefixed with Ctrl + b, in contrast to screen which is prefixed by Ctrl + a. You can cycle through windows by pressing Ctrl + b, n (next window) and Ctrl + b, p (previous window). You can jump to a window by pressing Ctrl + b, <number> or by pressing Ctrl + b, w and choosing a window interractively. Finally, you can kill a window and all its panes by Ctrl + b, &. This means pressing Ctrl + b, releasing the Ctrl key, then pressing Shift + 7, which sends the '&' key. Alternatively, you can kill a window by killing all of its panes.
Here's a summary of window commands you should know:
Ctrl + b, c- Create windowCtrl + b, n- Next windowCtrl + b, p- Previous windowCtrl + b, w- Select a window interactivelyCtrl + b, 0..9- Jump to a windowCtrl + b, &- Kill a window
Panes
Panes are part of a window and may be tiled. When you create a window you get a single pane.
Here's a summary of pane commands you should know:
Ctrl + b, "- Split the pane into two, top and bottomCtrl + b, %- Split the pane into two, left and rightCtrl + b, {- Swap the current pane with the previous paneCtrl + b, }- Swap the current pane with the next paneCtrl + b, x- Kill a paneCtrl + b, z- Toggle zoom in on a paneCtrl + b, q- Briefly display pane indexes
