
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.
Installing Tmux
Installing 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:
tmux
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:
Ctrl+b
?
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
Type Ctrl+b
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 + c
Create a new window (with shell)Ctrl-b + w
Choose window from a listCtrl-b + 0
Switch to window 0 (by number )Ctrl-b + ,
Rename the current windowCtrl-b + %
Split current pane horizontally into two panesCtrl-b + "
Split current pane vertically into two panesCtrl-b + o
Go to the next paneCtrl-b + ;
Toggle between the current and previous paneCtrl-b + x
Close the current pane
Detaching from Tmux Session
To detach from the Tmux session and return to your normal shell type:
Ctrl+b
d
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:
tmux ls
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 copy_session
.
For instance, to attach to session copy_session
, you would type:
tmux attach-session -t copy_session
Conclusion
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.
Leave a Reply