This tutorial explains how to install and basic use of Tmux.
What is tmux?
Tmux is a terminal multiplexer. It allows you to access a tmux terminal using multiple virtual terminals. It means within one terminal window you can open multiple windows and split-views. Each window occupies the entire screen and can be split into rectangular panes.
This also means that sudden disconnects from a server running tmux will not kill the processes running inside the tmux session.
tmux is an alternative of GNU Screen.
tmux is pretty straightforward on most distributions.
Install Tmux on Ubuntu and Debian
sudo apt install tmux
Installing Tmux on CentOS and Fedora
sudo yum install tmux
Install Tmux on macOS
brew install tmux
Starting Your First Tmux Session
For your first session simply start
tmux with a new session:
This will create a new tmux session and start a shell in that window. This window shows a green status bar with information about current session.
You can now run your first
tmux command. For example, to get a list of all commands, you would type:
Creating Tmux Session with Name
When have multiple sessions, it is difficult to find. We can create session by giving name which will be very useful to identify. To create a session with name, run tmux command as following:
tmux new -s session_name
Here, you should replace
session_name with your appropriate name.
Working with Tmux Windows and Panes
c in shell to create a new window. A list of all windows is shown on the status line at the bottom of the screen.
Below are some most common commands for managing Tmux windows and panes:
Ctrl-b + cCreate a new window (with shell)
Ctrl-b + wChoose window from a list
Ctrl-b + 0Switch to window 0 (by number )
Ctrl-b + ,Rename the current window
Ctrl-b + %Split current pane horizontally into two panes
Ctrl-b + "Split current pane vertically into two panes
Ctrl-b + oGo to the next pane
Ctrl-b + ;Toggle between the current and previous pane
Ctrl-b + xClose the current pane
Detaching from Tmux Session
To detach from the Tmux session and return to your normal shell type:
It will keep continue program which are running on the Tmux session.
Re-attaching to Tmux Session
You can attach to a session by name so we need name of the session first. To get a list of the currently running sessions type:
The name of the session is the first column of the output.
0: 1 windows (created Wed May 14 17:30:14 2020) [158x35] copy_session: 1 windows (created Wed May 15 18:17:18 2020) [78x35]
Above you can see there are two running Tmux sessions. The first one is named
0 and the second one
For instance, to attach to session
copy_session, you would type:
tmux attach-session -t copy_session
In this tutorial, you learned how to use Tmux to resume the sessions even after disconnected. Now you can start use of the Tmux to create multiple screen windows from a single session, detach and resume screen sessions.
To learn more about Tmux visit Screen User’s Manual page.
Feel free to leave a comment if you have any questions.