tmux
There are a couple of labs that are made easier / more efficient if we make use of 'tmux'
Last updated
Was this helpful?
There are a couple of labs that are made easier / more efficient if we make use of 'tmux'
Last updated
Was this helpful?
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!
Clear your terminal
Print a little text so we can easily identify this as our original terminal session
Launch 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.\
Print a little text so we can easily identify this as our 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 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!\
Detach from tmux
- 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
\
View a list of current tmux sessions
We can can 're-attach' the tmux session
Next challenge, we will horizontally split your terminal window
- 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\
You can move between the panes
Your white insertion character should have jumped to the lower window Up / Down, arrow keys also work
You 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
Hop back to the lower pane
View the interface IP addresses
That is enough excitement, time to halt the processes and quit tmux in the lower pane
This kills the pane, you are left with your single window, still running ping
Stop the ping
and
Confirm that there are now no tmux sessions running
(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.