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.
- It can improve the stability, and increase the execution speed of workflows.
- It enables visualization of problems in a new way.
- 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.
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.
A certain workflow is more efficient with two windows aligned next to each other e.g. code and server, code and console ect.
- Manually arrange windows next to each other.
- During the day resize them, and continually realign them.
- Split the current tmux window into two panes
- resize the terminal window, and tmux will proportinally resize the panes
An external box needs to run a long script ( like an install script )
- SSH into the machine and start the script
- Keep the session open because ending it will close all processes, and the script will fail.
- SSH into the machine and start tmux
- Start the script and feel free to disconnect ( on purpose, or accidentally)
- Later on, ssh back in and attach to the tmux session to check on the progress
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.
- Individually open each tab again, and be extra careful next time
- Open a new terminal window and attach to the tmux session, everything is still there.
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 .
- Individually open each tab, and run each command in sequence
- Write a tmux script that opens all the tabs, and executes commands in sequence
- Meanwhile, go and talk with a buddy about how awesome Bob Dylan is.
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:
- My videos which will let you start using tmux immediately, and gradually show more features as time goes on.
- Purchase this book that takes about two weeks to read / get up to speed ( this is how I learned tmux )
$ man tmuxwill get experienced unix users up to speed for free