tmux https://www.youtube.com/watch?v=U41BTVZLKB0 https://tmuxcheatsheet.com/ ![Tmux Cheat Sheet & Quick Reference _ Session, window, pane and more.pdf](../../_resources/Tmux%20Cheat%20Sheet%20&%20Quick%20Reference%20_%20Session,%20wind.pdf) - Start a new window with `tmux` command - At the bottom-left of screen there is `[0] 0:bash* ` `[0]` : session name `0` from `0:bash` : index `bash` : windows name `*` : current window - to start a session with custom name use `tmux new -s backups` or `tmux new-session -s backups`. to rename current session use `c-b $`. to close the particular session use `tmux kill-ses -t session_name`. To close current session go to command mode by `c-b :` then type `kill-session` and hit enter. - to create a new window use `c-b c` means press Ctrl+B then release them and instantly press c. to go to next window press `c-b n` and to previous window `c-b p`. to specfic window index press `c-b INDEX`(eg: `c-b 1` to go to 2nd window as 2nd window index is 1). to kill current window use `c-b &`. - when we start a process say `htop` that window name will be changed to `htop`. but in order to change window to custom name press `c-b ,` then type type name and enter - **Attach/dettach mode**: If we start a service like nodejs code by `npm start` or any other and donr want terminal to be open and just run in background we need to detach it by `c-b d`. this will detach whole session. To reattach to recent session use `tmux a` or `tmux at`, `tmux attach`, `tmux attach-session`. To reattach to particular session use `tmux a -t backups` `-t` means target - to list tmux sessions use `tmux ls` or `tmux list-sessions` - **Switching** : when in tmux, to switch between sessions use `c-b s` which will presents a tui screen to choose session from and for windows switching use `c-b w`. - To get list of keyboard shotcuts use `c-b ?` - Splitting panes : To switch panes horizontally use `c-b %` and for vertically use `c-b "`. To go to last active pane press `c-b ;` and for navigating use `c-b arrow-keys` for respective direction. To close current pane use `c-b x`. - to scroll press `c-b [` then use arrowkeys/pgup/pgdown keys to scroll - **Icons** : start tmux with `tmux -u` to enable unicode support.   automatic adding and running commands in tmux ```sh #!/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```