PostsWhy You May Be Missing Out If You Dont Use TMUX
Posted 02/04/2014

Tmux is one of the 10 skills every developer should master. It takes one week to get started, and saves hours of work and frustration.

Tmux is a modern incarnation of the GNU Screen program. Between the two, tmux has a more active group of developers. As such, most open tmux bugs are usually fixed faster. Greater development activity, and added features are why I use tmux over Screen. However, this article mostly showcases basic features which both technologies include.

Feel free to give either program a try. Both improve a workflow in essentially the same way. It's easy to switch between using either program because they are very similar.

Why use tmux?

Answer the following questions to evaluate if tmux can benefit you:

If you answered yes to any of those questions, then tmux will be useful to you.

  1. It can improve the stability, and increase the execution speed of workflows.
  2. It enables visualization of problems in a new way.
  3. It is easy to install, and works on most *nix platforms.

How does it work?

Tmux stands for terminal multiplexer.

tmux = terminal multiplexer

A terminal multiplexer is a program that can load many terminal windows within one. Don't let this complex verbiage discourage you!!! Using tmux is not very complicated, I promise.

The tmux man page ($ man tmux) explains the features that tmux offers.

(tmux) enables a number of terminals to be created, accessed, and controlled from a single screen. tmux may be detached from a screen and continue running in the background, then later reattached.

Tmux is a service that runs in the background. When attached to a tmux session, it enables interaction with the windows it controls. When the attached shell exits; tmux detaches, but remains running in the background. As such, a separate shell can reattach back into the tmux session. The session will continue in tmux with or without attached users. Any running programs in the session operate as if they were active the whole time.

Tmux can manage multiple sessions at the same time. Within each session, any number of windows can be created. Windows can also be split into both vertical and horizontal panes. Tmux can be controlled by scripts, and automate repetitive workflow tasks.

Go Learn It: Skip down to a list of next steps if you are sold on giving tmux a try.

Use Cases

Here are a few example use cases for tmux. They highlight some ways that tmux can be used to improve day to day workflows. Please share your own use cases in the comments section.

Debugging

A certain workflow is more efficient with two windows aligned next to each other e.g. code and server, code and console ect.

Without Tmux

  1. Manually arrange windows next to each other.
  2. During the day resize them, and continually realign them.

With Tmux

  1. Split the current tmux window into two panes
  2. resize the terminal window, and tmux will proportinally resize the panes
miniature-article

SSH

An external box needs to run a long script ( like an install script )

Without Tmux

  1. SSH into the machine and start the script
  2. Keep the session open because ending it will close all processes, and the script will fail.

With Tmux

  1. SSH into the machine and start tmux
  2. Start the script and feel free to disconnect ( on purpose, or accidentally)
  3. Later on, ssh back in and attach to the tmux session to check on the progress
miniature-article

Accidentally Closing A Bunch Of Tabs

There are a bunch of terminal tabs and windows open. At some point another app needs to be closed. However, the terminal application gets closed by accident. Now, the lost terminal windows need to be restored.

Without Tmux

  1. Individually open each tab again, and be extra careful next time

With Tmux

  1. Open a new terminal window and attach to the tmux session, everything is still there.
miniature-article

Morning set up

On a certain project, several tasks need to be completed before work can begin e.g.

$ cd project
$ git pull
$ start server
[Open a new tab]
$ cd project
$ start db
[Open a new tab]
$ cd project
$ start console
[Open a new tab]
$ cd project
$ vim .

Without Tmux

  1. Individually open each tab, and run each command in sequence

With Tmux

  1. Write a tmux script that opens all the tabs, and executes commands in sequence
  2. Meanwhile, go and talk with a buddy about how awesome Bob Dylan is.
miniature-article

What to do

This article intentionally does not show how to use tmux. That topic is a bit too long and confusing to condense into a single post. As such, here is a high level guide of the next steps that can be taken to learn tmux.

get tmux before doing anything else. Install it with a package manager: sudo [yum|apt-get|brew] install tmux]

Then choose one or all of these ways to learn:

  1. My videos which will let you start using tmux immediately, and gradually show more features as time goes on.
  2. Purchase this book that takes about two weeks to read / get up to speed ( this is how I learned tmux )
  3. Reading $ man tmux will get experienced unix users up to speed for free

Further Reading

  1. Interview with the author of tmux
  2. Movies: tmux Tunes by codriffs
  3. Book: tmux: Productive Mouse-Free Development