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 look at how to terminate a pane and window when you are inside a tmux window and from outside of tmux as well.

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, check this article.

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>

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.