DebugPointer
Published on

How to exit nested Tmux session

How to exit nested Tmux session

Tmux is one of the most useful tool when it comes to using a linux terminal.

Tmux is a terminal multiplexer, it allows a user to access multiple terminals (or windows), each running a separate program, while providing a single screen to work on. Tmux is useful for running more than one command-line program at the same time, increasing productivity and the way you work.

Let's consider the default prefix for tmux, which is Ctrl-B and let's go over the commands below using the same.

Let's look at how to terminate a pane and window when you are inside a tmux window and from outside of tmux as well.

Exit a nested tmux session

Let's look at detaching a tmux, tmux detach -E takes a shell command as argument, which is executed. Here is the snippet from its documentation for the same-

detach-client [-aP] [-E shell-command] [-s target-session] [-t target-client]

So, we will use-

detach-client -E <shell-command>

To exit a nested tmux session, you have to just use the following keyboard shortcuts.

At first, let's configure a linux function by adding the following in the ~/.bashrc or ~/.bash_profile.

tm() { tmux detach -E "tmux new -A -s '$1'"; }

Now you can use

tm 3

You can also exit a tmux session or in case you are in a tmux session and you are looking to detach from the session, that's fairly simple using the Ctrl-B + d command.

You can reset a tmux config in case you feel some of your tmux plugins are not working as expected and start with a clean config.

I hope this tutorial for exiting nested tmux session was useful. You can also check out the complete tmux cheatsheet of keyboard shortcuts and mouse shortcuts.