tmux

There are a couple of labs that are made easier / more efficient if we make use of 'tmux'

Introduction

circle-info

What is tmux?

tmux is a terminal multiplexer that allows access to multiple terminal sessions from a single window referred to as a session. Think of it like a 'window manager' for the terminal.

  • a multiplexer is just 'multi-tasking with multiple applications simultaneously'

  • a session is where the applications are visible

  • a window is the desktop in the text realm containing its own screen

  • a pane is where the application is and where we perform the operations

Inside tmux we can:

  • multitask inside the terminal and run multiple applications

  • have multiple command lines (panes) in the same window

  • have multiple windows

  • switch between multiple workspaces, like virtual desktops but for text. How cool!

Thus, tmux allows us to split these terminals into panes which you can then move, resize, and switch between. We can also detach and reattach later from the same device, or even a different device!

micro tmux LAB

  1. Clear your terminal

    clear
  2. Print a little text so we can easily identify this as our original terminal session

    echo 'This is my original terminal window'
  3. Launch tmux

    tmux

    Ok, that was the easy part. We should see a green bar at the bottom of the terminal. We're inside. We're in tmux.\

  4. Print a little text so we can easily identify this as our tmux session

    echo 'This is my tmux session'
  5. Great! to proceed, we need to interact with tmux, in order to this we need to get familiar with a new concept, the prefix key. The prefix key is how we can send commands specifically to tmux rather than the terminal in the pane. The default tmux prefix is <Ctrl b> While holding down the control key, press b. And then release both keys at the same time. This feels weird the first time you do it, but you'll soon commit this to muscle memory. But... Nothing happened We did not follow our prefix with an instruction!\

  6. Detach from tmux

    Ctrl+b d

    - Press control down and hold it. - Press b and hold it - Release both keys at the same time - Tap d Ok! You've done it! Hopefully you see your text 'This is my original terminal window' You have successfully detached from the tmux session Please note that tmux and your session are still running in the background \

  7. View a list of current tmux sessions

    tmux ls
  8. We can can 're-attach' the tmux session

    tmux attach
  9. Next challenge, we will horizontally split your terminal window

    Ctrl+b "

    - Press control down and hold it - Press b and hold it - Release both keys at the same time - Press shift hold it down - Press " - Release both keys Now your window has been split into 2x horizontal panes\

  10. You can move between the panes

    Ctrl+b o

    Your white insertion character should have jumped to the lower window Up / Down, arrow keys also work

    Ctrl+b up-arrow

    You now have 2x terminal shells available to you, on the same screen

  11. Hop back to the top panel

  12. Set a ping going in the top panel

    ping 169.254.42.1
  13. Hop back to the lower pane

    Ctrl+b down-arrow
  14. View the interface IP addresses

    ip address
  15. That is enough excitement, time to halt the processes and quit tmux in the lower pane

    exit

    This kills the pane, you are left with your single window, still running ping

  16. Stop the ping

    Ctrl+c

    and

    exit
  17. Confirm that there are now no tmux sessions running

    tmux ls

tmux quick reference

(optional) panes:

(advanced) need to see some scrollback and scroll up in a pane?

(advanced) don't like the default ctrl+b leader key binding? you can rebind/remap it.

Add set -g prefix C-a to your config.

Further Reading on tmux

Last updated

Was this helpful?