Tmux – Terminal MUltipleXerLife With tmux ssh into a system and YOU START TMUX! In tmux, you start...
Transcript of Tmux – Terminal MUltipleXerLife With tmux ssh into a system and YOU START TMUX! In tmux, you start...
Tmux – Terminal MUltipleXer
JaxLUG - Travis Phillips - 03/16/2016
What is a Terminal Multiplexer?
“A terminal multiplexer is a software application that can be used to multiplex several virtual consoles, allowing a user to access multiple separate login sessions inside a single terminal window, or detach and reattach sessions from a terminal.”
- Wikipedia
Why and When to Use One?
● Monitoring● Developer Environment● Learning● Switching between local and remote shells● Managing multiple systems concurrently.
Example: Developer Environment
Life Without tmux
● You ssh into a system● You start a large tar or dd operation in the
shell.● You need to close the ssh session due to
low battery on the laptop or you need to head to the office.
● Without tmux, prepare to stay where you or lose your work, the shell dies on disconnect from ssh...
Life With tmux● ssh into a system and YOU START TMUX!● In tmux, you start a large tar or dd operation.● You need to close the ssh session due to
low battery on the laptop or you need to head to the office.
● You detach from the tmux session.● Close your ssh session.● Head to the machine and hop on a local
shell and reattach tmux to your session and keep working! :-)
Hierarchy of tmux
● tmux can be thought of as a Hierarchy of 3 object levels.
– Sessions
– Windows
– Panes
Hierarchy
Starting Tmux
● The must basic way to start tmux is to simple run 'tmux' in a shell.
– This will start a session that will be assigned a number (starting at zero and incrementing up as more get created.)
Starting Tmux
Looks Like a Shell...Now What?
● Tmux uses hotkey sequences.● Sequence is and interrupt then a key or
combo– Interrupt is ctrl+b by default.
● IMPORTANT YOU KNOW THIS!
– Then a key or combo of keys is pressed to accomplish desired goal.
● Pay attention to case on letters, it DOES Matter!
● How do we know what the key or keys are?
Help is on the Way!● One by land, two by sea, right there in front of me...
● Tmux has a built in list of shortcut keys.● If you remember just one pair of keystrokes,
let it be this one as it can tell you the rest.● That combo is: <interrupt>+?
– Remember <interrupt> is ctrl+b
● So we press ctrl+b, don't hold it, just press it. Then hold shift and hit the '?' key (shift is needed for question mark, otherwise the key will produce '/')
The Help Menu Appears!
Sessions: What are They?
Sessions: What are They?● At the end of the day, tmux is a client to
connect to the “Sessions”.● Sessions are used to manage windows for
that "session".● Should be used to logically manage
functionality or the purpose of that shell session.
● Sessions can be attached to and detacted from at will.
– Useful for switching between ssh to local shells without losing your work.
Starting a Session● Sessions have names.
– When we started tmux, we didn't specify one● A number was automatically assigned.
– We can also specify one when we start it.● $ tmux new -s Testing
Un-named vs Named Sessions
Un-named (Got “0” as name)
Named “Testing” (Got “Testing” as name)
Renaming a Session● If you are in tmux in a session and want to
rename it:– Use <interrupt>, then $
– Basically: ● press ctrl+b, don't hold it, just press it. ● Hold shift, Then hit '$'.
● At the bottom, It will prompt you for a new name
● New name can't match an existing session name. These must be unique!
Renaming a Session
Detaching from a Sessions● If you want tmux to detach from a session:
– Use <interrupt>, then d
– Basically: ● press ctrl+b, don't hold it, just press it. ● Then hit 'd'. ● Note the case on 'd'. Do NOT hold shift, ctrl,
alt, or anything else when pressing 'd'.
● All Programs remain running!– Great for multi-tasking!
– Programs will remain running in a session, even if you disconnect from ssh!
Detaching from a Sessions
Listing Sessions● How do you know what sessions are there?● Outside of the session run one of the
following commands:– $ tmux list-session
● OR
– $ tmux list-sessions
● They do the same thing, but either works, which is nice!
Listing Sessions
Reattach to a Sessions● How do Reattach to a sessions?● Run the following command:
– $ tmux attach-session -t <session_name>● Think of “-t” as “target”
● This will reconnect you to a session.
Skipping Windows for a Minute Let's Talk about Panes
Panes: What are They?● A pane is a section of a window (like a
window pane, right?)● Panes allow you to partition off a window.● Each pane will basically run it's own shell
and can do it's own thing.● This allows you great usage of the real
estate your monitor(s) provides by allowing you to use all of.
● By default, a window is one pane.● If all panes are closed, a window will be
closed.
Splitting a Pane Vertically● To add more panes, you simply split existing● To split a pane vertically:
– <interrupt>, Then “ (double quote)
– Basically: ● press ctrl+b, don't hold it, just press it. ● Hold shift, Then hit “ (double quote).
● This will split the pane with a horizonal line, but it's called 'vertical' because the panes stack on top of each other
Splitting a Pane Vertically
Splitting a Pane Horizontally● To split a pane horizontally:
– <interrupt>, Then “%”
– Basically: ● press ctrl+b, don't hold it, just press it. ● Hold shift, Then hit %
● This will split the pane with a Vertical line, but it's called 'Horizontally' because the panes stack left and right of each other.
Splitting a Pane Horizontally
Switching Between Panes● To switch between panes:
– <interrupt>, Then <a directional arrow key>
– Basically: ● press ctrl+b, don't hold it, just press it. ● Then hit an arrow key in the direction you
want to go. DO NOT hold shift or Ctrl or anything else during this step.
Resizing Panes● To resize a pane:
– Make sure the pane you want to resize is selected.
– <interrupt>, Then ctrl+<a directional arrow key>
– Basically: ● press ctrl+b, don't hold it, just press it. ● Then HOLD Ctrl and hit an arrow key in the
direction you want to push/pull the pane separators attached to the selected pane.
Resizing Panes
Interrupt; then ctrl+<up_arrow> a few times
Bottom Pane is selected
Deleting Panes● To delete a pane:
– Make sure the pane you want to delete is selected.
– <interrupt>, Then “x”
– Basically: ● press ctrl+b, don't hold it, just press it. ● Then press “x”. DO NOT hold shift or ctrl or
anything.● It will prompt you to confirm if you want to
delete the pane, type “y” to delete it.
● Deleting the last pane will delete a window as well. If it's the only window, it will delete the session and close tmux.
Deleting Panes
Zooming Panes● Sometimes, a pane may have a lot of info on
it. You can “zoom” to full screen that pane.● To zoom a pane:
– Make sure the pane you want to zoom is selected.
– <interrupt>, Then “z” to zoom in
– Basically: ● press ctrl+b, don't hold it, just press it. ● Then press “z”. DO NOT hold shift or ctrl or
anything.
– Use <interrupt>, Then “z” again to zoom out
Now Let's Circle Back to Windows
Windows: What are They?● Sessions manage windows.
– A session may have several windows.
● Windows provide a workspace to setup panes.
● Windows can used to group logical pane together (e.g: a set of panes for monitoring process may go in one window, etc)
● Windows can be named.● Windows can be quickly switched acrossed.
Creating a Window● A session creates a window by default.● To add more:
– <interrupt>, Then “c”
– Basically:● press ctrl+b, don't hold it, just press it. ● Then hit the letter “c”. DO NOT hold shift or
Ctrl or anything else during this step.
Creating a Window
Naming a Window● A name is basically a label to make easier
for the user to identify it.● To Rename a window:
– Make sure the window you want to rename is selected.
– <interrupt>, Then “,” (comma)
– Basically:● press ctrl+b, don't hold it, just press it. ● Then hit the “,” key. DO NOT hold shift or Ctrl
or anything else during this step.
– Type the name of the window in, hit enter.
Creating a Window
Window Switching: Next● To switch to the next window:
– <interrupt>, Then “n”
– Basically:● press ctrl+b, don't hold it, just press it. ● Then hit the letter “n”. DO NOT hold shift or
Ctrl or anything else during this step.
Window Switching: Previous● To switch to the previous window:
– <interrupt>, Then “p”
– Basically:● press ctrl+b, don't hold it, just press it. ● Then hit the letter “n”. DO NOT hold shift or
Ctrl or anything else during this step.
Window Switching: By Number● You may have noticed in the status bar there
are numbers next to the windows. You can use them to select a window by that number (at least with 0-9)
● To switch to a window by number:– <interrupt>, Then <number of window>
– Basically:● press ctrl+b, don't hold it, just press it. ● Then hit the number key of the window you
want. DO NOT hold shift or Ctrl or anything else during this step.
Window Switching: By List● You may also have tmux display a list of
windows, and let you select from the list using up and down arrows.
● To switch to a window by number:– <interrupt>, Then “w”
– Basically:● press ctrl+b, don't hold it, just press it. ● Then hit the letter “w”. DO NOT hold shift or
Ctrl or anything else during this step.
Window Switching: By List
Window Switching: Last Used● You may have been switching by numbers,
you have a way to toggle between the two using the same key sequence.
– You may have noticed the current window will have an “*”, and the last used has a “-”
● To switch to the last used window:– <interrupt>, Then “l” (lowercase L)
– Basically:● press ctrl+b, don't hold it, just press it. ● Then hit the letter “l”. DO NOT hold shift or
Ctrl or anything else during this step.
Extras!● Did you know that tmux has a built it clock :-)
– <interrupt>; then “t”
● Shift+PageUp doesn't work for scrolling, to scroll, you need to go into copy mode. Hit esc when finshed.
– <interrupt>; then “[”
● Most ncurses TUI apps work okay with it. I haven't run into any issues yet.
Clock With Seconds● I like the clock, but dislike it lacks seconds,
so like most things in Linux, you can chain your own using while, echo, date, and toilet.
● For monocolor clock:– while true; do clear; echo -e "$(date '+%H:
%M:%S')" | toilet -t --font mono9; sleep 1; done
● For a rainbow colored clock:– while true; do clear; echo -e "$(date '+%H:
%M:%S')" | toilet -t --gay --font mono9; sleep 1; done
Clock With Seconds: Mono
Clock With Seconds: Colored
Other Useful Monitors● htop - process monitor● nload - Network load monitor● wavemon - wifi signal & link quality monitor● Poor mans disk monitor:
– while true; do clear; echo -e "\033[32;1m\t...::[ 1 minute refresh disk monitor ]::..\n\033[0m"; df -h; sleep 60; done
Homework!● Learn how to use the config file.● Learn how to re-configure the interrupt
sequence.● Learn how to use the “vi mode” commands
in tmux.● Learn how to use the config so you can
launch a session and have it auto build it the way you want and save time not doing it by hand.
Q&A Time!
???? ?