How To Get Started with tmux

tmux tmux

Quite simply, tmux allows you to run multiple terminal command lines at the same time side by side much like putting multiple windows next to each other so you see both simultaneously. It stands for “terminal multiplexer”, a fancy term for something so logical. Here are the basics to get you started with tmux quickly.

First of all, just run tmux. You will very likely have it in your system no matter which Linux or UNIX distribution you’re using. Otherwise you can get it from the tmux website. For MacOS, I suggest using brew package manager.

$ tmux

And you’re in. Not much has changed, but you should see the green bar at the bottom, which is the tmux status bar showing you which window you’re in, date and time, and the hostname of your system. The goodness is in the keyboard commands that you can now use to split the current window into multiple panes, or to create new windows with their own panes. You can then switch between panes and windows with ease.

The way keyboard commands work is by first pressing a shortcut CTRL-B, and then entering a character corresponding to a command. For example, to split the current window or pane into two vertical panes press CTRL-B %. Just press CTRL-B together, then enter the % normally, and it will split.

Here are a few of the basic commands that will have you up and going with tmux with ease:

  • CTRL-B % – split into two vertical panes (as mentioned)
  • CTRL-B “ – split into two horizontal panes
  • CTRL-B z – make the current pane full screen (press again to exit full screen)
  • CTRL-B arrow-key – switch between panes with arrow keys. For example
  • CTRL-B up-arrow – will switch to the pane above the currently active one.
  • CTRL-B c – create a new window. You will notice it indicated in the green status bar under a number.
  • CTRL-B number – switch to a window. To switch to a window 0, for example, press CTRL-B 0.

With these shortcuts you can create as many panes and windows as you need, and switch between them.

One more thing though. These sets of windows and panes are known as tmux sessions, and you can actually have multiple of them, and they are saved on the system so that they can be attached to different terminals you can in from.

You can detach from the current session with CTRL-B d, and you’ll end up back on the normal bare command line. Then you can run this to list all of the sessions with its numbers:

$ tmux -l

You’ll see something like:

0: 2 windows (created Tue Sep 2 18:30:02 2014) [237×55]
1: 1 windows (created Tue Sep 2 19:04:03 2014) [237×55]

Then you can attach to session 0, for example, with this command:

$ tmux attach -t 0

And if you no longer want a particular session you can kill it:

$ tmux kill-session -t 0

You can see the full breakdown of sessions, their windows, and their panes by issuing this command:

$ tmux info

Other useful commands with more information:

  • tmux list-keys
  • tmux list-commands
  • man tmux

See Also




Keep Learning

Follow me on Facebook, Twitter or Telegram:
Recommended
I learn with Educative: Educative
IT Consultancy
I'm a principal consultant with Tech Stack Solutions. I help with cloud architectrure, AWS deployments and automated management of Unix/Linux infrastructure. Get in touch!

Recent Tweets