Quick survival guide to tmux

Yep, this is the one. You can stop searching now. Just bookmark this page and come back here when you wanna remember some basic tmux keystroke or to setup a basic tmux config in a fresh Linux/Unix box 😉

Tmux is a terminal multiplexer. Wait, what? Why I need that?

  • You just connected to a Linux box through SSH, but hey, I want to run more than one command at a time! One shell is just not enough! Use tmux and you can have any number of terminals you want!
  • You connected to a Linux box through SSH, but hey, I want to run this command forever! Use tmux and you can run any command you want, detach from the terminal and it will keep running. For-eh-vah!
  • You love the good and old terminal, but you want more power to switch between shells really freaking fast. Use tmux!
  • You love both the terminal and Vim. Use tmux!

At Ubuntu:

sudo apt install tmux

At Mac:

brew install tmux

Download this minimal config file I created at your home sweet home. It has the minimal required to improve your UX on tmux:

wget https://gist.githubusercontent.com/automata/2a3e8a276b2fd05ae13d086422dc4140/raw/b09631ed5255d32a93cd2e1f396ef52631409fcd/tmux.conf -O ~/.tmux.conf

First, some basic concepts you'll become familiar with:

  • Tmux runs sessions where we can attach clients to
  • Each session can have many windows (listed on the bottom)
  • Each window can have many panes (the split panes you'll see)
  • Each new pane is a new bash prompt/terminal

To create a new session:


Now you can type C-b dand you'll dettach from the session. It's still running there, but you can exit you're SSH session now and attach again later… and all your beloved terminals will still be running 😍

To attach to a session you just created:

tmux a

To list existing sessions:

tmux ls

To attach to a specific session (see the first column from previous command, that's the id you need to use here. I'm using session zero):

tmux a -t 0

All commands start with C-b (C is the command key on Mac and thectrl key on Linux). So, basically always type the C-b prefix before almost every keystroke.

And here are the commands I use all the time and they should be enough for you to use tmux for weeks without having to worry much about it:

C-b c                     Create a new window
C-b | Split window vertically
C-b - Split window horizontally
C-b <arrow keys> Move between panes
C-b <h,j,k,l> Move between panes Vim-style
C-b <number> Go to window number n (listed at bottom)
C-b [ Enter in "scroll mode".
- Use arrows and page-down/up to move
- Type Enter to exit the mode.
C-b d Detach from session (to get back: tmux a)

Yep… and nope 😉 Tmux is an awesome piece of software with many, many more possibilities. Check its official Git repos for more and follow me on Twitter, I'll keep sharing tools and tricks I use daily as a Machine Learning engineer and CTO that can probably help you too! 👋

🤩 UPDATE: Wait, there's more!

From time to time I find more interesting commands, so I'll keep posting them here.

Sending the same command to all panes at once:

Let's say you have many panes open and you want to send the same commands to all of them:

C-b : setw synchronize-panes on

And to toggle it off:

C-b : setw synchronize-panes off

Removing other attached client:

You started your tmux and there's something wrong with the window size, it looks smaller than yours… maybe there's another client connected to your tmux running in a smaller window than yours! Just list the connected clients and remove the one you don't like:

C-b D

My panes are not aligned:

You can use the following command to iterate through many different layouts, maybe you're lucky and get your panes aligned as you wish:

C-b <space>

Coder, applied physicist and artist. I create algorithms that create. CTO at Extend AI. Half of 2aliens.