At this point, you will probably have a ton of terminal windows open and you will have trouble finding the one you want. To solve this problem, you can use a terminal multiplexer, a program that allows you to have multiple terminals open in the same terminal window.

There are many terminal multiplexers to choose from, but we recommend tmux.

Starting tmux

To start a new tmux session, you can simply run tmux or tmux new.

You can specify a name for the session using the -s flag. If you don’t specify a name, it will default to “0”. If you already have another tmux session running, the session name will be “1”.

$ tmux new -s MyNewSession
A Linux command line terminal window. Prompt shows directory '~/test $'. Green bar at bottom of window indicates that tmux is running.

Now you’ll notice a green (your color may vary) bar on the bottom of the terminal. You can use this terminal just like you would a normal terminal, but you probably want to open another terminal…

Creating Panes

You can have multiple panes inside the same window. Each pane will be it’s own separate terminal.

To split your window into two side-by-side panes, you can press CTRL+B, then :, and then type split-window -h. You could also press CTRL+B, then % to do the same.

A Linux command line terminal window. Prompt shows directory '~/test $'. Yellow bar at the bottom of window indicates that tmux is running and the tmux command ':split-window -h' has been entered.
A Linux command line terminal window split into two identical, side-by-side panes. Prompt in both panes shows directory '~/test $'. Green bar at the bottom of window indicates that tmux is running.

To split your window into two panes, one on top of the other, the process is similar. Either CTRL+B : then split-window -v or CTRL+B ".

A Linux command line terminal window split into two identical panes, one on top of the other. Prompt in both panes shows directory '~/test $'. Green bar at the bottom of window indicates that tmux is running.

You can do this as many times as you want in different combinations to get the perfect setup for you. Some examples:

A Linux command line terminal window split into two panes, one on top of the other. The bottom pane is further split into two side-by-side panes. Prompt in all panes shows directory '~/test $'. Green bar at the bottom of the window indicates that tmux is running.
A Linux command line terminal window split into two side-by-side panes. The right pane is further split into two panes, one on top of the other. Prompt in all panes shows directory '~/test $'. Green bar at the bottom of the window indicates that tmux is running.

Creating Windows

So what happens if you have your panes set up perfectly, but you suddenly need a new window? That’s as easy as CTRL+B : and then new-window. You can even give your window a name new-window -n Testing.

A Linux command line terminal window split into two side-by-side panes. The right pane is further split into two panes, one on top of the other. Prompt in all panes shows directory '~/test $'. Yellow bar at the bottom of the window indicates that tmux is running and the tmux command ':new-window -n Testing' has been entered.
A Linux command line terminal window. Prompt shows directory '~/test $'. Green bar at the bottom of the window indicates that tmux is running with two windows numbered '0' and '1'.

Now, you’re probably asking yourself how you can switch between panes and windows.

To switch between panes, simply press CTRL+B and then press the arrow key in the direction your want your cursor to move. You can also press CTRL+B q to display pane numbers, and then press the number your want to switch to that pane.

A Linux command line terminal window split into two side-by-side panes. The right pane is further split into two panes, one on top of the other. Prompt in all panes shows directory '~/test $'. Green bar at the bottom of the window indicates that tmux is running. Large numbers in the center of each pane indicate the ID number for each pane ('0' for the left pane, '1' for the top right pane, and '2' for the bottom right pane).

To switch between windows, press CTRL+B and then the number corresponding to your window. In the screenshot above, you can see a 0: and a 1: in the window names. Those are your window numbers.

Closing Panes & Windows

To close your active pane, simply type exit or press CTRL+D.

To close your active window, close all of its panes.



Tags: instructions