Last Updated: Aug 25, 2024
Tmux is a powerful tool that can help you manage multiple terminal sessions on a single terminal screen. It allows you to split your terminal window into multiple panes, each of which you can use to run different commands or programs. You can also create multiple windows within a single tmux session, allowing you to switch between multiple sessions, windows and panes.
Let's just get started with tmux 🔥
I'm assuming that you have already installed tmux in your system. In order to verify that tmux is installed or not, you can run the following command in your terminal.
It should output something like this: tmux 3.2a depending upon the version of tmux that you have already installed.
In order to get started with tmux sessions, let's first learn, how we can create a new session
In order to create a new tmux session, run the following command in your terminal.
A new tmux session will be created.
You will see a status bar at the bottom of your terminal window. It will show you the session name, system info & datetime.
In order to detach from a tmux session, you can press the prefix key, Ctrl + b
and then d
. This will detach you from the session and you will be back to your normal terminal.
After detaching, you will see a screen like this.
You can also create a named session by running the following command.
Just replace <session-name>
with the name of your session.
Let's say, I want to create a tmux session with name my-session then i will run the following command.
It will create a brand new tmux session with name my-session.
You can list all the tmux sessions by running the following command.
It will list all the tmux sessions that are currently running.
Let's say that just detached from a tmux session, and you want to re-attach to that session. You can do that by running the following command.
It will re-attach you to the last session that you were in.
You can also attach to a specific session by running the following command.
Just replace <session-name>
with the name of your session.
If you are already inside of a tmux session, you can list all the running tmux sessions by pressing the prefix key, Ctrl + b
and then s
.
It will open up a sessions list view that will list out all the running tmux sessions.
Let's say that there are multiple tmux sessions running, you are already attached to a tmux session and you want to switch to another session. In order to do that, Just press the prefix key, Ctrl + b
and then s
.
It will open up a sessions list view that will list out all the running tmux sessions. You can navigate through the list using the arrow keys
or j & k
and then press Enter
to switch to that session.
In order to rename a tmux session, you can press the prefix key, Ctrl + b
and then :
, it will open up a command prompt at the bottom of your terminal. You can then run the following command.
Just replace <old-session-name>
with the name of your old session and <new-session-name>
with the name of your new session.
While killing a session, you can either be inside of a tmux session or outside of a tmux session.
If you are outside of a tmux session, you can run the following command.
If you are inside of a tmux session.
You can press the prefix key, Ctrl + b
and then :
, it will open up a command prompt at the bottom of your terminal. You can then run the following command.
Just replace <session-name>
with the name of your session.
OR
You can use the sessions list view inside of tmux to kill sessions by navigating to the session with the arrow keys
or j & k
and pressing the x
key. It will ask you to confirm the action, just press y
to confirm and that particular session will be killed.
Note: Just make sure that you are not killing the currently active session.
That's it for tmux sessions 🚀