54
Tmux – T erminal MU ltipleX er JaxLUG - Travis Phillips - 03/16/2016

Tmux – Terminal MUltipleXerLife 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

  • Upload
    others

  • View
    22

  • Download
    1

Embed Size (px)

Citation preview

Page 1: Tmux – Terminal MUltipleXerLife 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

Tmux – Terminal MUltipleXer

JaxLUG - Travis Phillips - 03/16/2016

Page 2: Tmux – Terminal MUltipleXerLife 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

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

Page 3: Tmux – Terminal MUltipleXerLife 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

Why and When to Use One?

● Monitoring● Developer Environment● Learning● Switching between local and remote shells● Managing multiple systems concurrently.

Page 4: Tmux – Terminal MUltipleXerLife 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

Example: Developer Environment

Page 5: Tmux – Terminal MUltipleXerLife 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

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...

Page 6: Tmux – Terminal MUltipleXerLife 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

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! :-)

Page 7: Tmux – Terminal MUltipleXerLife 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

Hierarchy of tmux

● tmux can be thought of as a Hierarchy of 3 object levels.

– Sessions

– Windows

– Panes

Page 8: Tmux – Terminal MUltipleXerLife 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

Hierarchy

Page 9: Tmux – Terminal MUltipleXerLife 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

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.)

● More on this later.

Page 10: Tmux – Terminal MUltipleXerLife 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

Starting Tmux

Page 11: Tmux – Terminal MUltipleXerLife 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

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?

Page 12: Tmux – Terminal MUltipleXerLife 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

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 '/')

Page 13: Tmux – Terminal MUltipleXerLife 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

The Help Menu Appears!

Page 14: Tmux – Terminal MUltipleXerLife 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

Sessions: What are They?

Page 15: Tmux – Terminal MUltipleXerLife 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

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.

Page 16: Tmux – Terminal MUltipleXerLife 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

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

Page 17: Tmux – Terminal MUltipleXerLife 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

Un-named vs Named Sessions

Un-named (Got “0” as name)

Named “Testing” (Got “Testing” as name)

Page 18: Tmux – Terminal MUltipleXerLife 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

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!

Page 19: Tmux – Terminal MUltipleXerLife 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

Renaming a Session

Page 20: Tmux – Terminal MUltipleXerLife 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

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!

Page 21: Tmux – Terminal MUltipleXerLife 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

Detaching from a Sessions

Page 22: Tmux – Terminal MUltipleXerLife 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

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!

Page 23: Tmux – Terminal MUltipleXerLife 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

Listing Sessions

Page 24: Tmux – Terminal MUltipleXerLife 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

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.

Page 25: Tmux – Terminal MUltipleXerLife 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

Skipping Windows for a Minute Let's Talk about Panes

Page 26: Tmux – Terminal MUltipleXerLife 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

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.

Page 27: Tmux – Terminal MUltipleXerLife 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

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

Page 28: Tmux – Terminal MUltipleXerLife 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

Splitting a Pane Vertically

Page 29: Tmux – Terminal MUltipleXerLife 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

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.

Page 30: Tmux – Terminal MUltipleXerLife 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

Splitting a Pane Horizontally

Page 31: Tmux – Terminal MUltipleXerLife 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

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.

Page 32: Tmux – Terminal MUltipleXerLife 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

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.

Page 33: Tmux – Terminal MUltipleXerLife 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

Resizing Panes

Interrupt; then ctrl+<up_arrow> a few times

Bottom Pane is selected

Page 34: Tmux – Terminal MUltipleXerLife 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

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.

Page 35: Tmux – Terminal MUltipleXerLife 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

Deleting Panes

Page 36: Tmux – Terminal MUltipleXerLife 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

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

Page 37: Tmux – Terminal MUltipleXerLife 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

Now Let's Circle Back to Windows

Page 38: Tmux – Terminal MUltipleXerLife 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

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.

Page 39: Tmux – Terminal MUltipleXerLife 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

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.

Page 40: Tmux – Terminal MUltipleXerLife 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

Creating a Window

Page 41: Tmux – Terminal MUltipleXerLife 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

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.

Page 42: Tmux – Terminal MUltipleXerLife 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

Creating a Window

Page 43: Tmux – Terminal MUltipleXerLife 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

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.

Page 44: Tmux – Terminal MUltipleXerLife 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

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.

Page 45: Tmux – Terminal MUltipleXerLife 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

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.

Page 46: Tmux – Terminal MUltipleXerLife 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

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.

Page 47: Tmux – Terminal MUltipleXerLife 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

Window Switching: By List

Page 48: Tmux – Terminal MUltipleXerLife 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

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.

Page 49: Tmux – Terminal MUltipleXerLife 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

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.

Page 50: Tmux – Terminal MUltipleXerLife 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

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

Page 51: Tmux – Terminal MUltipleXerLife 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

Clock With Seconds: Mono

Clock With Seconds: Colored

Page 52: Tmux – Terminal MUltipleXerLife 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

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

Page 53: Tmux – Terminal MUltipleXerLife 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

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.

Page 54: Tmux – Terminal MUltipleXerLife 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

Q&A Time!

???? ?