See my other tutorials.

tmux lets you keep things running persistently on servers, so you can disconnect and connect as needed without interrupting tasks that are in progress.

Use-cases: compiling code, running security scans, etc.

It’s best to install tmux using your existing OS package management options.

macOS

$ brew install tmux

Ubuntu Linux

$ apt install tmux

If you invoke tmux by itself, you’ll get dropped into a new session. And if you exit this session, you drop right back into your normal shell.

The ctrl–b shortcut is good to memorize.

$ tmux

Creating named sessions lets you reattach more easily.

$ tmux new -s session-name

You want a pause between the shortcut and the following command.

To detach from a session you invoke the shortcut (ctrl-b)—followed by d , for detatch, or by typing detach explicitly.

$ ctrl–b–d

$ tmux detach

Consider remapping CAPSLOCK to CONTROL in your OS to make this easier.

You can—and often will—have multiple tmux sessions on a single system, so you want to be able to see what they are.

You can also show sessions using the shortcut ctrl–b–s.

$ tmux ls

Now that we can see those sessions, you can either connect to one by session name, or by number.

The session names start at 0 and increment upwards.

$ tmux attach -t 0

tmux a will connect you to the first available session.

$ tmux attach -t session-name

There are times when you’ll want to destroy a session outright, and that can be done similar to attaching to one.

$ tmux kill-session -t session-name

You can also kill tmux altogether with killall tmux.

I don’t use this functionality myself.

Another feature of tmux is the ability to break your session into more discreet components, called windows and panes. These are good for organizing multiple activities in a logical way.

Basically, tmux sessions have windows, and windows have panes. Here’s how I conceptualize the structure.

Sessions are for an overall theme, such as work, or experimentation, or sysadmin.

are for an overall theme, such as work, or experimentation, or sysadmin. Windows are for projects within that theme. So perhaps within your experimentation session you have a window titled noderestapi, and one titled lua sample.

are for projects within that theme. So perhaps within your experimentation session you have a window titled noderestapi, and one titled lua sample. Panes are for views within your current project. So within your sysadmin session, which has a logs window, you may have a few panes for access logs, error logs, and system logs.

These all play off of the ctrl-b shortcut.

Basics

? get help

Session management

s list sessions

list sessions $ rename the current session

rename the current session d detach from the current session

Windows

c create a new window

create a new window , rename the current window

rename the current window w list windows

list windows % split horizontally

split horizontally " split vertically

split vertically n change to the next window

change to the next window p change to the previous window

change to the previous window 0 to 9 select windows 0 through 9

Panes

% create a horizontal pane

create a horizontal pane " create a vertical pane

create a vertical pane h move to the left pane. *

move to the left pane. * j move to the pane below *

move to the pane below * l move to the right pane *

move to the right pane * k move to the pane above *

move to the pane above * q show pane numbers

show pane numbers o toggle between panes

toggle between panes } swap with next pane

swap with next pane { swap with previous pane

swap with previous pane ! break the pane out of the window

break the pane out of the window x kill the current pane

Parting thoughts

Here are a few tips I’ve picked up over the years using tmux .

Consider using as few sessions and windows as possible. Humans aren’t as good at multitasking as we think we are, and while it feels powerful to have 47 panes open it’s usually not as functional as you’d imagine. When you do use windows and panes, take the time to name them. They are indeed useful, but switching between sessions and windows is supremely annoying when they’re all labeled 0, 1, and 2. Start with a basic config and get used to it before you get silly with it. I’ve seen multiple people spend hours configuring vim or tmux only to confuse themselves and abandon the project altogether. Start simple.

Notes