tmux
There are a couple of labs that are made easier / more efficient if we make use of 'tmux'
Introduction
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
Clear your terminal
clearPrint a little text so we can easily identify this as our original terminal session
echo 'This is my original terminal window'Launch tmux
tmuxOk, that was the easy part. We should see a green bar at the bottom of the terminal. We're inside. We're in tmux.\
Print a little text so we can easily identify this as our tmux session
echo 'This is my tmux session'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 keyis 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 thecontrolkey, pressb. 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!\Detach from tmux
Ctrl+b d- Press
controldown and hold it. - Pressband hold it - Release both keys at the same time - TapdOk! 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
\View a list of current tmux sessions
tmux lsWe can can 're-attach' the tmux session
tmux attachNext challenge, we will horizontally split your terminal window
Ctrl+b "- Press
controldown and hold it - Pressband hold it - Release both keys at the same time - Pressshifthold it down - Press"- Release both keys Now your window has been split into 2x horizontal panes\You can move between the panes
Ctrl+b oYour white insertion character should have jumped to the lower window Up / Down, arrow keys also work
Ctrl+b up-arrowYou now have 2x terminal shells available to you, on the same screen
Hop back to the top panel
Set a ping going in the top panel
ping 169.254.42.1Hop back to the lower pane
Ctrl+b down-arrowView the interface IP addresses
ip addressThat is enough excitement, time to halt the processes and quit tmux in the lower pane
exitThis kills the pane, you are left with your single window, still running ping
Stop the ping
Ctrl+cand
exitConfirm 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?