TMUX - Sessions Guide 🚀

Last Updated: Aug 25, 2024

TMUX - Sessions Guide 🚀

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.


tmux -V

It should output something like this: tmux 3.2a depending upon the version of tmux that you have already installed.



Sessions

In order to get started with tmux sessions, let's first learn, how we can create a new session


Creating a tmux session

In order to create a new tmux session, run the following command in your terminal.


tmux

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.


Blog post image

Detaching from a tmux session

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.


Blog post image

Creating a named tmux session

You can also create a named session by running the following command.


tmux new -s <session-name>

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.


tmux new -s my-session

It will create a brand new tmux session with name my-session.


Blog post image

Listing all the tmux sessions (Outside of tmux)

You can list all the tmux sessions by running the following command.


tmux ls

It will list all the tmux sessions that are currently running.


Blog post image

Attaching to a tmux session

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.


tmux a

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.


tmux a -t <session-name>

Just replace <session-name> with the name of your session.



Listing all the tmux sessions (Inside of tmux)

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.


Blog post image

Switching between 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.



Renaming a tmux 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.


rename-session -t <old-session-name> <new-session-name>

Just replace <old-session-name> with the name of your old session and <new-session-name> with the name of your new session.



Killing a tmux 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.


tmux kill-session -t <session-name>

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.


kill-session -t <session-name>

Just replace <session-name> with the name of your session.


Blog post image

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.


Blog post image

Note: Just make sure that you are not killing the currently active session.


That's it for tmux sessions 🚀

Talha Imran

+923114048235

talhaimran284@gmail.com