Tmux is a terminal multiplexer. It allows you to run and manage several command prompts simultaneously from one tmux session.<\/p>\n\n\n\n
Tmux uses a client\/server model, which allows it to persist connections. You can start a session from one computer, run several programs running in it, and then disconnect. You can later reconnect to the same session from a different computer and the same programs will be running.<\/p>\n\n\n\n
On Debian and Ubuntu systems, install tmux with apt.<\/p>\n\n\n\n
$ sudo apt-get update && sudo apt-get -y install tmux\n<\/code><\/pre>\n\n\n\nInstall tmux on Redhat, CentOS, and Other RHEL-Based Distributions<\/h2>\n\n\n\n
On Redhat, CentOS, and other RHEL-based systems, install tmux with yum.<\/p>\n\n\n\n
$ sudo yum install update && sudo yum -y install tmux\n<\/code><\/pre>\n\n\n\nTerminology<\/h2>\n\n\n\n\n- Pane<\/strong> – A pane is simply a terminal prompt.<\/li>\n\n\n\n
- Window<\/strong> – A window holds multiple panes (terminals) on one screen.<\/li>\n\n\n\n
- Session<\/strong> – A session has multiple windows.<\/li>\n\n\n\n
- Server<\/strong> – A server holds multiple sessions. It runs in the background and ensures the persistence of the sessions.<\/li>\n<\/ul>\n\n\n\n
Start a New tmux Session<\/h2>\n\n\n\n$ tmux new -s start\n<\/code><\/pre>\n\n\n\nYou will see a bar at the bottom of the screen with the session name tmux created, start<\/strong>, in brackets. This is because tmux automatically logs in with your user account when it creates new panes.<\/p>\n\n\n\nManeuvering in tmux<\/h2>\n\n\n\n
Once inside a tmux session, you use a prefix key to trigger commands to tell tmux what to do. The default prefix key is CTRL<\/kbd> + B<\/kbd>. For example, if you want to tell tmux to create a new pane by splitting your screen into two vertical sections, you first type CTRL<\/kbd> + B<\/kbd>, then %<\/kbd>.<\/p>\n\n\n\nCreate Multiple Panes<\/h2>\n\n\n\n
If you typed CTRL<\/kbd> + B<\/kbd>, then %<\/kbd> as shown above, then you have two panes on your screen.<\/p>\n\n\n\n\n- Split the current pane into two horizontal sections by typing CTRL<\/kbd> + B<\/kbd>, then \"<\/kbd>.<\/li>\n\n\n\n
- To cycle through all three panes, type CTRL<\/kbd> + B<\/kbd>, then O<\/kbd>.<\/li>\n<\/ul>\n\n\n\n
Switch Between Panes<\/h2>\n\n\n\n
To switch between different open panes, use the arrow keys with the prefix.<\/p>\n\n\n\n
\n- CTRL<\/kbd> + B<\/kbd>, then UP<\/kbd>: Go to the pane above the current pane.<\/li>\n\n\n\n
- CTRL<\/kbd> + B<\/kbd>, then DOWN<\/kbd>: Go to the pane below the current pane.<\/li>\n\n\n\n
- CTRL<\/kbd> + B<\/kbd>, then LEFT<\/kbd>: Go to the pane on the left of the current pane.<\/li>\n\n\n\n
- CTRL<\/kbd> + B<\/kbd>, then RIGHT<\/kbd>: Go to the pane on the right of the current pane.<\/li>\n<\/ul>\n\n\n\n
Create Multiple Windows<\/h2>\n\n\n\n\n- Create a new window in the start<\/strong> session. Type CTRL<\/kbd> + B<\/kbd>, then C<\/kbd> to open a new blank terminal.<\/li>\n\n\n\n
- Split this terminal into two horizontal panes with CTRL<\/kbd> + B<\/kbd>, then \"<\/kbd>.<\/li>\n\n\n\n
- Create a third window with CTRL<\/kbd> + B<\/kbd>, then C<\/kbd>.You will see a new blank terminal again.<\/li>\n\n\n\n
- Issue the command
tmux list-windows<\/code>, then press ENTER<\/kbd> to confirm that you have three windows opened.<\/li>\n\n\n\n- Use CTRL<\/kbd> + B<\/kbd>, then N<\/kbd> to cycle between the three windows created.<\/li>\n<\/ol>\n\n\n\n
Attach and Detach to\/from a Session<\/h2>\n\n\n\n\n- Use CTRL<\/kbd> + B<\/kbd>, then D<\/kbd> to detach from your current session.<\/li>\n\n\n\n
- Reconnect to your session with
tmux attach -t YOUR_SESSION_NAME<\/code>.<\/li>\n\n\n\n- Use CTRL<\/kbd> + B<\/kbd>, then N<\/kbd> to cycle between the windows in your session.<\/li>\n<\/ul>\n\n\n\n
Common Key Bindings<\/h2>\n\n\n\n\n- CTRL<\/kbd> + B<\/kbd>, then C<\/kbd> : Create new window.<\/li>\n\n\n\n
- CTRL<\/kbd> + B<\/kbd>, then ,<\/kbd> : Rename a window.<\/li>\n\n\n\n
- CTRL<\/kbd> + B<\/kbd>, then N<\/kbd> : Move to the next window.<\/li>\n\n\n\n
- CTRL<\/kbd> + B<\/kbd>, then P<\/kbd> : Move to the previous window.<\/li>\n\n\n\n
- CTRL<\/kbd> + B<\/kbd>, then &<\/kbd> : Kill current window.<\/li>\n\n\n\n
- CTRL<\/kbd> + B<\/kbd>, then %<\/kbd> : Split current pane into two (vertically).<\/li>\n\n\n\n
- CTRL<\/kbd> + B<\/kbd>, then \"<\/kbd> : Split current pane into two (horizontally).<\/li>\n\n\n\n
- CTRL<\/kbd> + B<\/kbd>, then O<\/kbd> : Switch to next pane.<\/li>\n\n\n\n
- CTRL<\/kbd> + B<\/kbd>, then Q<\/kbd> : Show pane numbers (then type a # to switch to it).<\/li>\n\n\n\n
- CTRL<\/kbd> + B<\/kbd>, then D<\/kbd> : Detach from current session.<\/li>\n\n\n\n
- CTRL<\/kbd> + B<\/kbd>, then ?<\/kbd> : List all key bindings.<\/li>\n\n\n\n
- CTRL<\/kbd> + B<\/kbd>, then X<\/kbd>: Kill the active pane (after pressing Y<\/kbd> to confirm).<\/li>\n\n\n\n
- CTRL<\/kbd> + B<\/kbd>, then W<\/kbd>: Show an overview of all active windows and panes. Use the arrow keys to move through the list of windows and see a preview of the selected window. Press ENTER<\/kbd> to switch to the selected window. Press ESC<\/kbd> to exit the overview.<\/li>\n<\/ul>\n\n\n\n
Common Commands<\/h3>\n\n\n\n\ntmux list-sessions<\/code> – List existing tmux sessions.<\/li>\n\n\n\ntmux new -s session-name<\/code> – Create a new tmux session named session-name.<\/li>\n\n\n\ntmux attach -t session-name<\/code> – Connect to an existing tmux session named session-name.<\/li>\n\n\n\ntmux switch -t session-name<\/code> – Switches to an existing tmux session named session-name.<\/li>\n<\/ul>\n\n\n\nUse Vim Key Bindings to Switch Between Panes<\/h3>\n\n\n\n
Instead of using the arrow keys to switch between different panes, you can use the Vim keys H<\/kbd>, J<\/kbd>, K<\/kbd>, L<\/kbd>. To do this, update the tmux configuration file ~\/.tmux.conf<\/code>. If this file doesn’t exist, create it.<\/p>\n\n\n\nAdd these lines (the first line is a comment) to the configuration file to enable pane navigation using Vim keys:<\/p>\n\n\n\n
# hjkl pane traversal\n\nbind h select-pane -L\n\nbind j select-pane -D\n\nbind k select-pane -U\n\nbind l select-pane -R\n<\/code><\/pre>\n\n\n\nAfter updating the configuration file, restart tmux. You can load the new configuration without restarting tmux by sourcing<\/em> the updated configuration file:<\/p>\n\n\n\ntmux source-file ~\/.tmux.conf\n<\/code><\/pre>\n\n\n\nThe Meta Key<\/h2>\n\n\n\n
Many of the key bindings in the following sections are based on the Meta key. On most modern computers and keyboards, the Meta key is not one specific key. Depending on the system settings and the terminal emulator in use, the Meta key could be bound to either ESC<\/kbd>, ALT<\/kbd>, COMMAND<\/kbd>, WIN<\/kbd>, or Opt<\/code>. Where you see META<\/kbd> as part of a key binding, try using the ESC<\/kbd> key. If it doesn’t work, try one of the other keys mentioned above.<\/p>\n\n\n\nAdjust Pane Size<\/h2>\n\n\n\n
When a window has multiple panes, you can change the size of individual panes.<\/p>\n\n\n\n
\n- To change the pane size, press and hold the prefix (CTRL<\/kbd> + B<\/kbd>), and simultaneously press one of the arrow keys.<\/li>\n\n\n\n
- Hold down CTRL<\/kbd> + B<\/kbd>, and simultaneously press either UP<\/kbd> or DOWN<\/kbd>: Change the height of the pane.<\/li>\n\n\n\n
- Hold down CTRL<\/kbd> + B<\/kbd>, and simultaneously press either LEFT<\/kbd> or RIGHT<\/kbd>: Change the width of the pane.<\/li>\n<\/ul>\n\n\n\n
The above key combinations resize the pane “continuously” as long as they are held pressed. To resize the pane one step at a time:<\/p>\n\n\n\n
\n- CTRL<\/kbd> + B<\/kbd>, then META<\/kbd> + either UP<\/kbd> or DOWN<\/kbd>: Change the height of the pane.<\/li>\n\n\n\n
- CTRL<\/kbd> + B<\/kbd>, then META<\/kbd> + either LEFT<\/kbd> or RIGHT<\/kbd>: Change the width of the pane.<\/li>\n<\/ul>\n\n\n\n
Whether a particular key combination (above) increases or decreases the dimensions of the pane depends on the positioning of that pane relative to other panes.<\/p>\n\n\n\n
If the terminal emulator supports mouse use, you can resize panes by dragging their borders.<\/p>\n\n\n\n
Choose a Preset Pane Layout<\/h2>\n\n\n\n
Tmux has five different preset layouts for arranging multiple panes in a window:<\/p>\n\n\n\n
\n- All panes are stacked side-by-side.<\/li>\n\n\n\n
- All panes are stacked on top of each other.<\/li>\n\n\n\n
- The main pane takes up the entire screen width and the other panes are stacked side-by-side below it<\/li>\n\n\n\n
- The main pane takes up the entire screen height and the others panes are stacked beside it on top of each other<\/li>\n\n\n\n
- All panes are arranged in a grid.<\/li>\n<\/ol>\n\n\n\n
Start tmux and create 4 (or any number of) panes.<\/p>\n\n\n\n
To cycle through the different preset layouts use CTRL<\/kbd> + B<\/kbd>, then SPACE<\/kbd><\/p>\n\n\n\nYou can also choose a specific layout:<\/p>\n\n\n\n
\n- CTRL<\/kbd> + B<\/kbd>, then META<\/kbd> + 1<\/kbd>: Switch to layout 1.<\/li>\n\n\n\n
- CTRL<\/kbd> + B<\/kbd>, then META<\/kbd> + 2<\/kbd>: Switch to layout 2.<\/li>\n\n\n\n
- CTRL<\/kbd> + B<\/kbd>, then META<\/kbd> + 3<\/kbd>: Switch to layout 3.<\/li>\n\n\n\n
- CTRL<\/kbd> + B<\/kbd>, then META<\/kbd> + 4<\/kbd>: Switch to layout 4.<\/li>\n\n\n\n
- CTRL<\/kbd> + B<\/kbd>, then META<\/kbd> + 5<\/kbd>: Switch to layout 5.<\/li>\n<\/ul>\n\n\n\n
Swapping Pane Positions<\/h2>\n\n\n\n
When a window has multiple panes, you can move the panes around and swap their positions.<\/p>\n\n\n\n
\nNote: As described previously, CTRL<\/kbd> + B<\/kbd>, then O<\/kbd> cycles the cursor through the different panes. The above sequence is for cycling the positions of the panes themselves.<\/p>\n<\/blockquote>\n\n\n\n\n- CTRL<\/kbd> + B<\/kbd>, then META<\/kbd> + O<\/kbd> cycles the positions of the panes clockwise.<\/li>\n\n\n\n
- CTRL<\/kbd> + B<\/kbd>, then CTRL<\/kbd> + O<\/kbd> cycles the positions of the panes counterclockwise.<\/li>\n<\/ul>\n\n\n\n
Detach and Reattach Individual Panes<\/h2>\n\n\n\n
In a layout with multiple panes in a window, it is sometimes necessary to move a pane to a different location. Swapping pane positions (as described above) isn’t always sufficient, because it disturbs the positions of all the other panes. It is also sometimes necessary to move a pane to a different window in the same session.<\/p>\n\n\n\n
Use the command break-pane<\/code> in the tmux command prompt to detach a pane from the window. join-pane<\/code> reattaches the pane.<\/p>\n\n\n\nTo access the tmux command prompt, press the prefix