Tmux is a terminal multiplexer. It allows you to run and manage several command prompts simultaneously from one tmux session.
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.
On Debian and Ubuntu systems, install tmux with apt.
$ sudo apt-get update && sudo apt-get -y install tmux
On Redhat, CentOS, and other RHEL-based systems, install tmux with yum.
$ sudo yum install update && sudo yum -y install tmux
Pane - A pane is simply a terminal prompt.
Window - A window holds multiple panes (terminals) on one screen.
Session - A session has multiple windows.
$ tmux new -s start
You will see a bar at the bottom of the screen with the session name tmux created, start, in brackets. This is because Tmux automatically logs in with your user account when it creates new panes.
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 + B. 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 + B, then %.
If you typed CTRL + B, then % as shown above, then you have two panes on your screen.
Split the current pane into two horizontal sections by typing CTRL + B, then ".
Create a new window in the start session. Type CTRL + B, then C to open a new blank terminal.
Split this terminal into two horizontal panes with CTRL + B, then ".
Create a third window with CTRL + B, then C.
You will see a new blank terminal again.
Issue the command
tmux list-windows, then press ENTER to confirm that you have three windows opened.
Use CTRL + B, then N to cycle between the three windows created.
Use CTRL + B, then D to detach from your current session.
Reconnect to your session with
tmux attach -t YOUR_SESSION_NAME.
Use CTRL + B, then N to cycle between the windows in your session.
CTRL + B, then C : Create new window.
CTRL + B, then , : Rename a window.
CTRL + B, then N : Move to the next window.
CTRL + B, then P : Move to the previous window.
CTRL + B, then & : Kill current window.
CTRL + B, then % : Split current pane into two (vertically).
CTRL + B, then " : Split current pane into two (horizontally).
CTRL + B, then O : Switch to next pane.
CTRL + B, then Q : Show pane numbers (then type a # to switch to it).
CTRL + B, then D : Detach from current session.
CTRL + B, then ? : List all key bindings.
tmux list-sessions - List existing tmux sessions.
tmux new -s session-name - Create a new tmux session named session-name.
tmux attach -t session-name - Connect to an existing tmux session named session-name.
tmux switch -t session-name - Switches to an existing tmux session named session-name.