2.7 KiB
2.7 KiB
tmux
https://www.youtube.com/watch?v=U41BTVZLKB0
https://tmuxcheatsheet.com/
- Start a new window with
tmuxcommand - At the bottom-left of screen there is
[0] 0:bash*[0]: session name0from0:bash: indexbash: windows name*: current window - to start a session with custom name use
tmux new -s backupsortmux new-session -s backups. to rename current session usec-b $. to close the particular session usetmux kill-ses -t session_name. To close current session go to command mode byc-b :then typekill-sessionand hit enter. - to create a new window use
c-b cmeans press Ctrl+B then release them and instantly press c. to go to next window pressc-b nand to previous windowc-b p. to specfic window index pressc-b INDEX(eg:c-b 1to go to 2nd window as 2nd window index is 1). to kill current window usec-b &. - when we start a process say
htopthat window name will be changed tohtop. but in order to change window to custom name pressc-b ,then type type name and enter - Attach/dettach mode: If we start a service like nodejs code by
npm startor any other and donr want terminal to be open and just run in background we need to detach it byc-b d. this will detach whole session. To reattach to recent session usetmux aortmux at,tmux attach,tmux attach-session. To reattach to particular session usetmux a -t backups-tmeans target - to list tmux sessions use
tmux lsortmux list-sessions - Switching : when in tmux, to switch between sessions use
c-b swhich will presents a tui screen to choose session from and for windows switching usec-b w. - To get list of keyboard shotcuts use
c-b ? - Splitting panes : To switch panes horizontally use
c-b %and for vertically usec-b ". To go to last active pane pressc-b ;and for navigating usec-b arrow-keysfor respective direction. To close current pane usec-b x. - to scroll press
c-b [then use arrowkeys/pgup/pgdown keys to scroll - Icons : start tmux with
tmux -uto enable unicode support.
automatic adding and running commands in tmux
#!/bin/bash
SESSION="my_session"
tmux new-session -d -s $SESSION
#C-m emulates pressing enter key
tmux send-keys -t $SESSION:0 "htop" C-m
#create a new window of index 1 with name 'logs'
tmux new-window -t $SESSION:1 -n "logs"
tmux send-keys -t $SESSION:1 "history" C-m
tmux new-window -t $SESSION:2 -n "monitor"
tmux send-keys -t $SESSION:2 "while true; do echo 'Monitoring...'; sleep 5; done" C-m
tmux attach-session -t $SESSION```