Tmux
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
=====================================================================
- to enter tmux $ tmux
==================================== Panes =====================================
- for new Pane
- Ctrl + b then ‘%’ ( for vertical Pane ) ( for % = Shift + 5 ) **
- Note: Ctrl key should be leaved before pressing ‘%’
- Ctrl + b then “ ( horizontal Pane ) (quetations) ( for “ = Shift + “ ) **
- Ctrl + b then ‘%’ ( for vertical Pane ) ( for % = Shift + 5 ) **
-
to switch between Panes $ Ctrl + b then arrow-keys **
$ Ctrl + B then ‘o’ // to next pane ( not zero…it’s o - Open’s o) **
-
resizing the Panes Ctrl + b then Ctrl + arrow-keys **
- Note: after prefix key ( Ctrl + b ) again Ctrl + arrow keys - for exit (close) Pane $ exit
================================== windows =========================
-
to create a new window
$ Ctrl + b then c *
- active window is marked with ‘*’
- window name is shown at the bottom-left
-
to switch between windows
$ Ctrl + b then ‘window-number’ // window number we can see at the bottom-left *
-
to rename window
$ Ctrl + b then , ( comma )
- then enter text the press enter
-
to exit window $ exit
========================== Sessions =======================
- to dettach the current session
$ Ctrl + b then d **
- we can directly close the terminal also
-
to list tmux sessions $ tmux ls **
-
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 )
-
to rename session $ tmux rename-session -t session-number
-
to create session $ tmux new
-
to create session with name $ tmux new -s session_name **
-
to kill / stop session $ tmux kill-session -t session_name_or_number **
========================= Impornat ==============
- new session & command_to_execute from CMD
$ tmux new ‘command_to_execute’ **
eg: tmux new 'serve -p 3000'
-
new session & detach mode & command_to_execute from CMD
$ tmux new -d ‘command_to_execute’ **
eg: tmux new -d ‘serve -p 3000’
-
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’
-
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
-
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’