Tmux

Session = tmux session Pane = Terminal within tmux session Prefix Key = Ctrl + b

Window = Parent Terminal of Pane - one window can have any no of Panes

     - in one tmux sessions we can have multiple windows      

=====================================================================

  1. to enter tmux $ tmux

==================================== Panes =====================================

  1. for new Pane
    1. Ctrl + b then ‘%’ ( for vertical Pane ) ( for % = Shift + 5 ) **
      • Note: Ctrl key should be leaved before pressing ‘%’
    2. Ctrl + b then “ ( horizontal Pane ) (quetations) ( for “ = Shift + “ ) **
  2. to switch between Panes $ Ctrl + b then arrow-keys **

    $ Ctrl + B then ‘o’ // to next pane ( not zero…it’s o - Open’s o) **

  3. resizing the Panes Ctrl + b then Ctrl + arrow-keys **

    - Note: after prefix key ( Ctrl + b ) again Ctrl + arrow keys
    
  4. for exit (close) Pane $ exit

================================== windows =========================

  1. to create a new window

    $ Ctrl + b then c *

    • active window is marked with ‘*’
    • window name is shown at the bottom-left
  2. to switch between windows

    $ Ctrl + b then ‘window-number’ // window number we can see at the bottom-left *

  3. to rename window

    $ Ctrl + b then , ( comma )

    • then enter text the press enter
  4. to exit window $ exit

========================== Sessions =======================

  1. to dettach the current session $ Ctrl + b then d **
    • we can directly close the terminal also
  2. to list tmux sessions $ tmux ls **

  3. to attch session $ tmux attach -t session_name_or_number ( session-number we can see from the list ) **

    • ‘-t’ = target session

$ tmux attach ( attaches the last session )

  1. to rename session $ tmux rename-session -t session-number

  2. to create session $ tmux new

  3. to create session with name $ tmux new -s session_name **

  4. to kill / stop session $ tmux kill-session -t session_name_or_number **

========================= Impornat ==============

  1. new session & command_to_execute from CMD

$ tmux new ‘command_to_execute’ **

 eg: tmux new 'serve -p 3000'
  1. new session & detach mode & command_to_execute from CMD

    $ tmux new -d ‘command_to_execute’ **

    eg: tmux new -d ‘serve -p 3000’

  2. new session with name & detach mode & command_to_execute from CMD

    $ tmux new -s session_name -d ‘command_to_execute’ **

    eg: tmux new -s s1 -d ‘serve -p 3000’

  3. to add new pane to existing session from CMD ( by default detach mode)

$ tmux split-window -t session_name_or_number -v ‘command_to_execute’ **

eg: tmux split-window -t s1 -v ‘serve -p 4000’ eg: tmux split-window -t s1 -h ‘serve -p 5000’

   Note:-  '-v' for vertial split
           '-h' for horizontal split
           


   Note:-  Ctrl + b the % or "  executes split-window command under the hood         
  1. new session & multiple Panes in detach mode tmux new -s s1 -d ‘serve -p 3000’ \; split-window -h -t s1 ‘top’ # top is command *

    or tmux new -s s1 -d ‘serve -p 3000’ && tmux split-window -h -t s1 ‘top’