Tmux sessions

If you spend any time in the command line and are not using Tmux, you're really missing out.

Developers, DevOps and SysAdmins are always looking for tools to make their life more productive and easier to manage. Tmux is a favorite tool for many, for good reason.

So.. what exactly is Tmux?

The official term of Tmux is 'terminal multiplexer'. Tmux allows you to create saved sessions in your terminal, whether you're on your local machine or connected to a server via a ssh session.

Why is this helpful? For me, most of my work is done on my local machine. From day to day I switch between a range projects. Most are in the web development space, and each project requires a slightly different approach to how I interact with it via the command line.

The beauty of Tmux, is it allows me to create a terminal session for each project. I can close and re-open each one at any time, which saves me a bunch of time not having to change directories, fire up monitoring applications… etc, every time I want to step back into that project.

The real beauty of Tmux comes when you find yourself connecting to multiple servers frequently. (Actually, even just one!).

Imagine you're in the office, you have your new application running on a cloud server and you have everything set up over your ssh connection just how you like it.

In one tab you have Htop, in another you are sitting in a deeply nested directory you need to fire off most of your commands from, and have Vim open in another for any quick config edits.

Now imagine you returned home for the evening and remembered you forgot to save that last edit you made!?

With Tmux you can simply connect to that ssh session and return to that exact same terminal setup you had at work … Nice, right!?

Getting started

Installation

MacOS:

brew install tmux

Ubuntu:

sudo apt update
sudo apt install tmux

Red Hat / CentOS:

yum install tmux

Starting Tmux

Simply:

tmux

Sessions

Creating a new session (with name):

tmux new -s myname

Attaching back to that same session late:

tmux a -t myname

Listing all saved sessions:

tmux ls

Kill a session:

tmux kill-session -t myname

This is just the very basics of what you can do with Tmux.

As shown in my screen shot above, you can split panes (horizontal and vertical), create windows, and so much more. No more tabs or multiple terminal windows, you can control everything from your keyboard!

Here is a great Tmux cheatsheet Gist by Mohamed Alaa, which will give you a run down on all the basic default Tmux commands.

My tmux configuration can be found here.