DebugPointer
Published on

How to terminate pane and window in Tmux

How to terminate pane and window in Tmux

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.

Tmux is one of the "terminal multiplexer", it enables a number of terminals (or windows) to be accessed and controlled from a single terminal. It allows you to create a session on a remote box, run applications in that remote session, "detach" from the session, and re-"attach" when desired. It also has advanced features such as multiple windows and split views. Using tmux is recommend when running an interactive CLI program remotely. If you get disconnected from your session, you can re-attach as though nothing happened.

Let's consider the default prefix for tmux, which is Ctrl-B and let's go over the commands below using the same. In case you want to change the prefix of tmux you can do it as well.

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.

Kill a tmux pane

To kill a tmux pane, you have to switch and stay in the active pane which you want to terminate. Then, you can do the following keyboard default shortcut-

Ctrl-B + x

It's a series of 2 keyboard keysets you will have to press. You have to press Ctrl-B, then release the keys, then press x right after that.

OR

You can also run the tmux command in the command line to kill the pane-

tmux kill-pane -a -t <pane-number>

So, for example, if you want to kill the pane number 2, you can just run the following command -

tmux kill-window -a -t 2

OR

To kill the window that you are currently working in, you can do the following -

Ctrl-B
:
kill-pane -t <pane-number>
<enter-key>

An example where you can kill the window number 2 is as follows-

Ctrl-B
:
kill-pane -t 2
<enter-key>

Here, you will have to use the prefix Ctrl-B and then : to enter into a command entering mode. Then you can type kill-pane into it and press the Enter Key.

Kill a tmux window

You can kill a tmux window by killing all panes by pressing Ctrl-B + x several times until all panes are terminated.

You can also kill the window by pressing the following keyboard default shortcut-

Ctrl-B + &

OR

You can also run the tmux command in the command line to kill the window-

tmux kill-window -t <window-number>

So, for example, if you want to kill the window number 4, you can just run the following command -

tmux kill-window -t 4

OR

You can use the following to kill a specific window-

Ctrl-B
:
kill-window -t <window-number>
<enter-key>

An example where you can kill the window number 4 is as follows-

Ctrl-B
:
kill-window -t 4
<enter-key>

To kill the window that you are currently working in, you can do the following -

Ctrl-B
:
kill-window
<enter-key>

You can also exit from a tmux session, not just window or pane.

Here, you will have to use the prefix Ctrl-B and then : to enter into a command entering mode. Then you can type kill-window into it and press the Enter Key.

I hope this tutorial for killing panes and windows in tmux was useful. You can also check out the complete tmux cheatsheet of keyboard shortcuts and mouse shortcuts.